summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKnud Dollereder <knud.dollereder@qt.io>2022-08-04 15:59:45 +0200
committerKnud Dollereder <knud.dollereder@qt.io>2022-08-22 14:31:08 +0000
commitaea64ca1fa3af08a39ef748b2ae91a7d4590141e (patch)
treed2f5feb04b20ad5aa42ebb35eed2ac3b04f89b91
parent395e0560d4d4e2c9ab1c01bc39d5bcd3dc7c39a1 (diff)
downloadqt-creator-aea64ca1fa3af08a39ef748b2ae91a7d4590141e.tar.gz
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: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Aleksei German <aleksei.german@qt.io>
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp16
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.cpp21
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.h8
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp12
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h2
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp17
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.h4
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.cpp12
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/keyframeitem.h2
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/keyframe.cpp9
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/keyframe.h2
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 29e88e2581..18d838d2ff 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 b7bbf37051..bf6fe06e47 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<int>::lowest(), std::numeric_limits<int>::max());
m_startSpin->setValue(model->minimumTime());
+ m_startSpin->setFixedWidth(70);
connect(
m_startSpin, QOverload<int>::of(&QSpinBox::valueChanged),
@@ -117,6 +113,7 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
m_endSpin = new ValidatableSpinBox(validateEnd);
m_endSpin->setRange(std::numeric_limits<int>::lowest(), std::numeric_limits<int>::max());
m_endSpin->setValue(model->maximumTime());
+ m_endSpin->setFixedWidth(70);
connect(
m_endSpin, QOverload<int>::of(&QSpinBox::valueChanged),
@@ -128,6 +125,7 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
m_currentSpin->setMinimum(0);
m_currentSpin->setMaximum(std::numeric_limits<int>::max());
+ m_currentSpin->setFixedWidth(70);
connect(
m_currentSpin, QOverload<int>::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<double>(value)/100.0f);
+ });
+ addWidget(m_zoomSlider);
+}
+
+void CurveEditorToolBar::setZoom(double zoom)
+{
+ QSignalBlocker blocker(m_zoomSlider);
+ m_zoomSlider->setValue( static_cast<int>(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 25271245c6..7d3c02adb3 100644
--- a/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.h
+++ b/src/plugins/qmldesigner/components/curveeditor/curveeditortoolbar.h
@@ -26,6 +26,7 @@
#pragma once
#include <QSpinBox>
+#include <QSlider>
#include <QToolBar>
#include <QValidator>
#include <QWidget>
@@ -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 5b05309976..e6c99e7085 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 c6bdc6d3d4..0f0d5d5341 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 8ab71ace97..d01ffa47c7 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 917a8e7e2c..27b27a4a36 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 0dbb2d125f..171665cf2f 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 c7bfa02cd1..7d04bab209 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 085c230335..0b97764f9e 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 2757d229f5..13656859ec 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);