From aea64ca1fa3af08a39ef748b2ae91a7d4590141e Mon Sep 17 00:00:00 2001 From: Knud Dollereder Date: Thu, 4 Aug 2022 15:59:45 +0200 Subject: [PATCH] Add zoom slider to the curve editors toolbar Removed the "Set Default" button from the toolbar since it does the same as the "linear interpolation" button and space is rare in the toolbar. Fixes: QDS-6951 Change-Id: Ifdbf20af2e5365e9bf9b592783b872394cabb7eb Reviewed-by: Reviewed-by: Aleksei German --- .../components/curveeditor/curveeditor.cpp | 16 ++++++++++---- .../curveeditor/curveeditortoolbar.cpp | 21 ++++++++++++++----- .../curveeditor/curveeditortoolbar.h | 8 +++++-- .../curveeditor/detail/curveitem.cpp | 12 ----------- .../components/curveeditor/detail/curveitem.h | 2 -- .../curveeditor/detail/graphicsview.cpp | 17 ++++----------- .../curveeditor/detail/graphicsview.h | 4 ++-- .../curveeditor/detail/keyframeitem.cpp | 12 ----------- .../curveeditor/detail/keyframeitem.h | 2 -- .../components/curveeditor/keyframe.cpp | 9 -------- .../components/curveeditor/keyframe.h | 2 -- 11 files changed, 40 insertions(+), 65 deletions(-) diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp b/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp index 29e88e2581d..18d838d2ff1 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp @@ -71,10 +71,6 @@ CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent) box->addWidget(m_statusLine); setLayout(box); - connect(m_toolbar, &CurveEditorToolBar::defaultClicked, [this]() { - m_view->setDefaultInterpolation(); - }); - connect(m_toolbar, &CurveEditorToolBar::unifyClicked, [this]() { m_view->toggleUnified(); }); @@ -99,6 +95,13 @@ CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent) m_view->viewport()->update(); }); + connect(m_toolbar, &CurveEditorToolBar::zoomChanged, [this](double zoom) { + const bool wasBlocked = m_view->blockSignals(true); + m_view->setZoomX(zoom); + m_view->blockSignals(wasBlocked); + m_view->viewport()->update(); + }); + connect( m_view, &GraphicsView::currentFrameChanged, m_toolbar, &CurveEditorToolBar::setCurrentFrame); @@ -110,6 +113,11 @@ CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent) m_tree->selectionModel(), &SelectionModel::curvesSelected, m_view, &GraphicsView::updateSelection); + connect(m_view, &GraphicsView::zoomChanged, [this](double x, double y) { + Q_UNUSED(y); + m_toolbar->setZoom(x); + }); + auto updateTimeline = [this, model](bool validTimeline) { if (validTimeline) { updateStatusLine(); diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.cpp b/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.cpp index b7bbf370511..bf6fe06e47f 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.cpp @@ -67,7 +67,6 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent) QAction *tangentSplineAction = addAction( QIcon(":/curveeditor/images/tangetToolsSplineIcon.png"), "Spline"); - QAction *tangentDefaultAction = addAction(tr("Set Default")); QAction *tangentUnifyAction = addAction(tr("Unify")); auto setLinearInterpolation = [this]() { @@ -79,9 +78,6 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent) auto setSplineInterpolation = [this]() { emit interpolationClicked(Keyframe::Interpolation::Bezier); }; - auto setDefaultKeyframe = [this]() { - emit defaultClicked(); - }; auto toggleUnifyKeyframe = [this]() { emit unifyClicked(); }; @@ -89,7 +85,6 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent) connect(tangentLinearAction, &QAction::triggered, setLinearInterpolation); connect(tangentStepAction, &QAction::triggered, setStepInterpolation); connect(tangentSplineAction, &QAction::triggered, setSplineInterpolation); - connect(tangentDefaultAction, &QAction::triggered, setDefaultKeyframe); connect(tangentUnifyAction, &QAction::triggered, toggleUnifyKeyframe); auto validateStart = [this](int val) -> bool { @@ -100,6 +95,7 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent) m_startSpin = new ValidatableSpinBox(validateStart); m_startSpin->setRange(std::numeric_limits::lowest(), std::numeric_limits::max()); m_startSpin->setValue(model->minimumTime()); + m_startSpin->setFixedWidth(70); connect( m_startSpin, QOverload::of(&QSpinBox::valueChanged), @@ -117,6 +113,7 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent) m_endSpin = new ValidatableSpinBox(validateEnd); m_endSpin->setRange(std::numeric_limits::lowest(), std::numeric_limits::max()); m_endSpin->setValue(model->maximumTime()); + m_endSpin->setFixedWidth(70); connect( m_endSpin, QOverload::of(&QSpinBox::valueChanged), @@ -128,6 +125,7 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent) m_currentSpin->setMinimum(0); m_currentSpin->setMaximum(std::numeric_limits::max()); + m_currentSpin->setFixedWidth(70); connect( m_currentSpin, QOverload::of(&QSpinBox::valueChanged), @@ -150,6 +148,19 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent) auto *positionWidget = new QWidget; positionWidget->setLayout(positionBox); addWidget(positionWidget); + + m_zoomSlider = new QSlider(Qt::Horizontal); + m_zoomSlider->setRange(0, 100); + connect(m_zoomSlider, &QSlider::valueChanged, [this](int value) { + emit zoomChanged(static_cast(value)/100.0f); + }); + addWidget(m_zoomSlider); +} + +void CurveEditorToolBar::setZoom(double zoom) +{ + QSignalBlocker blocker(m_zoomSlider); + m_zoomSlider->setValue( static_cast(zoom*100)); } void CurveEditorToolBar::setCurrentFrame(int current, bool notify) diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.h b/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.h index 25271245c6e..7d3c02adb33 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.h +++ b/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.h @@ -26,6 +26,7 @@ #pragma once #include +#include #include #include #include @@ -53,8 +54,6 @@ class CurveEditorToolBar : public QToolBar Q_OBJECT signals: - void defaultClicked(); - void unifyClicked(); void interpolationClicked(Keyframe::Interpolation interpol); @@ -65,9 +64,13 @@ signals: void currentFrameChanged(int current); + void zoomChanged(double zoom); + public: CurveEditorToolBar(CurveEditorModel *model, QWidget* parent = nullptr); + void setZoom(double zoom); + void setCurrentFrame(int current, bool notify); void updateBoundsSilent(int start, int end); @@ -76,6 +79,7 @@ private: ValidatableSpinBox *m_startSpin; ValidatableSpinBox *m_endSpin; QSpinBox *m_currentSpin; + QSlider *m_zoomSlider; }; } // End namespace QmlDesigner. diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp index 5b053099763..e6c99e70859 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp @@ -458,18 +458,6 @@ void CurveItem::setInterpolation(Keyframe::Interpolation interpolation) emit curveChanged(id(), curve(true)); } -void CurveItem::setDefaultInterpolation() -{ - if (m_keyframes.empty()) - return; - - for (auto *frame : qAsConst(m_keyframes)) { - if (frame->selected()) - frame->setDefaultInterpolation(); - } - emit curveChanged(id(), curve(true)); -} - void CurveItem::toggleUnified() { if (m_keyframes.empty()) diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h index c6bdc6d3d4c..0f0d5d53414 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h +++ b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h @@ -125,8 +125,6 @@ public: void setInterpolation(Keyframe::Interpolation interpolation); - void setDefaultInterpolation(); - void toggleUnified(); void connect(GraphicsScene *scene); diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp index 8ab71ace978..d01ffa47c71 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp @@ -336,18 +336,6 @@ void GraphicsView::setInterpolation(Keyframe::Interpolation interpol) viewport()->update(); } -void GraphicsView::setDefaultInterpolation() -{ - const auto selectedCurves = m_scene->selectedCurves(); - for (auto *curve : selectedCurves) - curve->setDefaultInterpolation(); - - m_scene->setDirty(true); - - applyZoom(m_zoomX, m_zoomY); - viewport()->update(); -} - void GraphicsView::toggleUnified() { const auto selectedCurves = m_scene->selectedCurves(); @@ -569,7 +557,10 @@ void GraphicsView::applyZoom(double x, double y, const QPoint &pivot) } m_scene->doNotMoveItems(false); - this->update(); + + viewport()->update(); + + emit zoomChanged(m_zoomX, m_zoomY); } void GraphicsView::drawGrid(QPainter *painter) diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.h b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.h index 917a8e7e2c4..27b27a4a366 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.h +++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.h @@ -49,6 +49,8 @@ class GraphicsView : public QGraphicsView signals: void currentFrameChanged(int frame, bool notify); + void zoomChanged(double x, double y); + public: GraphicsView(CurveEditorModel *model, QWidget *parent = nullptr); @@ -112,8 +114,6 @@ public: void setInterpolation(Keyframe::Interpolation interpol); - void setDefaultInterpolation(); - void toggleUnified(); protected: diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp index 0dbb2d125f0..171665cf2f6 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp @@ -250,18 +250,6 @@ void KeyframeItem::setKeyframe(const Keyframe &keyframe) setPos(m_transform.map(m_frame.position())); } -void KeyframeItem::setDefaultInterpolation() -{ - if (!m_left || !m_right) - return; - - m_frame.setDefaultInterpolation(); - - setKeyframe(m_frame); - - emit redrawCurve(); -} - void KeyframeItem::toggleUnified() { if (!m_left || !m_right) diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h b/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h index c7bfa02cd18..7d04bab2099 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h +++ b/src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h @@ -92,8 +92,6 @@ public: void setKeyframe(const Keyframe &keyframe); - void setDefaultInterpolation(); - void toggleUnified(); void setActivated(bool active, HandleItem::Slot slot); diff --git a/src/plugins/qmldesigner/components/curveeditor/keyframe.cpp b/src/plugins/qmldesigner/components/curveeditor/keyframe.cpp index 085c230335c..0b97764f9e8 100644 --- a/src/plugins/qmldesigner/components/curveeditor/keyframe.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/keyframe.cpp @@ -154,15 +154,6 @@ void Keyframe::setPosition(const QPointF &pos) m_position = pos; } -void Keyframe::setDefaultInterpolation() -{ - auto leftToRight = QLineF(m_leftHandle, m_rightHandle); - leftToRight.translate(m_position - leftToRight.center()); - - m_leftHandle = leftToRight.p1(); - m_rightHandle = leftToRight.p2(); -} - void Keyframe::setUnified(bool unified) { m_unified = unified; diff --git a/src/plugins/qmldesigner/components/curveeditor/keyframe.h b/src/plugins/qmldesigner/components/curveeditor/keyframe.h index 2757d229f58..13656859ece 100644 --- a/src/plugins/qmldesigner/components/curveeditor/keyframe.h +++ b/src/plugins/qmldesigner/components/curveeditor/keyframe.h @@ -68,8 +68,6 @@ public: Interpolation interpolation() const; - void setDefaultInterpolation(); - void setUnified(bool unified); void setPosition(const QPointF &pos);