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>
This commit is contained in:
Knud Dollereder
2022-08-04 15:59:45 +02:00
parent 395e0560d4
commit aea64ca1fa
11 changed files with 40 additions and 65 deletions

View File

@@ -71,10 +71,6 @@ CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent)
box->addWidget(m_statusLine); box->addWidget(m_statusLine);
setLayout(box); setLayout(box);
connect(m_toolbar, &CurveEditorToolBar::defaultClicked, [this]() {
m_view->setDefaultInterpolation();
});
connect(m_toolbar, &CurveEditorToolBar::unifyClicked, [this]() { connect(m_toolbar, &CurveEditorToolBar::unifyClicked, [this]() {
m_view->toggleUnified(); m_view->toggleUnified();
}); });
@@ -99,6 +95,13 @@ CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent)
m_view->viewport()->update(); 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( connect(
m_view, &GraphicsView::currentFrameChanged, m_view, &GraphicsView::currentFrameChanged,
m_toolbar, &CurveEditorToolBar::setCurrentFrame); m_toolbar, &CurveEditorToolBar::setCurrentFrame);
@@ -110,6 +113,11 @@ CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent)
m_tree->selectionModel(), &SelectionModel::curvesSelected, m_tree->selectionModel(), &SelectionModel::curvesSelected,
m_view, &GraphicsView::updateSelection); 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) { auto updateTimeline = [this, model](bool validTimeline) {
if (validTimeline) { if (validTimeline) {
updateStatusLine(); updateStatusLine();

View File

@@ -67,7 +67,6 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
QAction *tangentSplineAction = addAction( QAction *tangentSplineAction = addAction(
QIcon(":/curveeditor/images/tangetToolsSplineIcon.png"), "Spline"); QIcon(":/curveeditor/images/tangetToolsSplineIcon.png"), "Spline");
QAction *tangentDefaultAction = addAction(tr("Set Default"));
QAction *tangentUnifyAction = addAction(tr("Unify")); QAction *tangentUnifyAction = addAction(tr("Unify"));
auto setLinearInterpolation = [this]() { auto setLinearInterpolation = [this]() {
@@ -79,9 +78,6 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
auto setSplineInterpolation = [this]() { auto setSplineInterpolation = [this]() {
emit interpolationClicked(Keyframe::Interpolation::Bezier); emit interpolationClicked(Keyframe::Interpolation::Bezier);
}; };
auto setDefaultKeyframe = [this]() {
emit defaultClicked();
};
auto toggleUnifyKeyframe = [this]() { auto toggleUnifyKeyframe = [this]() {
emit unifyClicked(); emit unifyClicked();
}; };
@@ -89,7 +85,6 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
connect(tangentLinearAction, &QAction::triggered, setLinearInterpolation); connect(tangentLinearAction, &QAction::triggered, setLinearInterpolation);
connect(tangentStepAction, &QAction::triggered, setStepInterpolation); connect(tangentStepAction, &QAction::triggered, setStepInterpolation);
connect(tangentSplineAction, &QAction::triggered, setSplineInterpolation); connect(tangentSplineAction, &QAction::triggered, setSplineInterpolation);
connect(tangentDefaultAction, &QAction::triggered, setDefaultKeyframe);
connect(tangentUnifyAction, &QAction::triggered, toggleUnifyKeyframe); connect(tangentUnifyAction, &QAction::triggered, toggleUnifyKeyframe);
auto validateStart = [this](int val) -> bool { auto validateStart = [this](int val) -> bool {
@@ -100,6 +95,7 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
m_startSpin = new ValidatableSpinBox(validateStart); m_startSpin = new ValidatableSpinBox(validateStart);
m_startSpin->setRange(std::numeric_limits<int>::lowest(), std::numeric_limits<int>::max()); m_startSpin->setRange(std::numeric_limits<int>::lowest(), std::numeric_limits<int>::max());
m_startSpin->setValue(model->minimumTime()); m_startSpin->setValue(model->minimumTime());
m_startSpin->setFixedWidth(70);
connect( connect(
m_startSpin, QOverload<int>::of(&QSpinBox::valueChanged), m_startSpin, QOverload<int>::of(&QSpinBox::valueChanged),
@@ -117,6 +113,7 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
m_endSpin = new ValidatableSpinBox(validateEnd); m_endSpin = new ValidatableSpinBox(validateEnd);
m_endSpin->setRange(std::numeric_limits<int>::lowest(), std::numeric_limits<int>::max()); m_endSpin->setRange(std::numeric_limits<int>::lowest(), std::numeric_limits<int>::max());
m_endSpin->setValue(model->maximumTime()); m_endSpin->setValue(model->maximumTime());
m_endSpin->setFixedWidth(70);
connect( connect(
m_endSpin, QOverload<int>::of(&QSpinBox::valueChanged), m_endSpin, QOverload<int>::of(&QSpinBox::valueChanged),
@@ -128,6 +125,7 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
m_currentSpin->setMinimum(0); m_currentSpin->setMinimum(0);
m_currentSpin->setMaximum(std::numeric_limits<int>::max()); m_currentSpin->setMaximum(std::numeric_limits<int>::max());
m_currentSpin->setFixedWidth(70);
connect( connect(
m_currentSpin, QOverload<int>::of(&QSpinBox::valueChanged), m_currentSpin, QOverload<int>::of(&QSpinBox::valueChanged),
@@ -150,6 +148,19 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
auto *positionWidget = new QWidget; auto *positionWidget = new QWidget;
positionWidget->setLayout(positionBox); positionWidget->setLayout(positionBox);
addWidget(positionWidget); 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) void CurveEditorToolBar::setCurrentFrame(int current, bool notify)

View File

@@ -26,6 +26,7 @@
#pragma once #pragma once
#include <QSpinBox> #include <QSpinBox>
#include <QSlider>
#include <QToolBar> #include <QToolBar>
#include <QValidator> #include <QValidator>
#include <QWidget> #include <QWidget>
@@ -53,8 +54,6 @@ class CurveEditorToolBar : public QToolBar
Q_OBJECT Q_OBJECT
signals: signals:
void defaultClicked();
void unifyClicked(); void unifyClicked();
void interpolationClicked(Keyframe::Interpolation interpol); void interpolationClicked(Keyframe::Interpolation interpol);
@@ -65,9 +64,13 @@ signals:
void currentFrameChanged(int current); void currentFrameChanged(int current);
void zoomChanged(double zoom);
public: public:
CurveEditorToolBar(CurveEditorModel *model, QWidget* parent = nullptr); CurveEditorToolBar(CurveEditorModel *model, QWidget* parent = nullptr);
void setZoom(double zoom);
void setCurrentFrame(int current, bool notify); void setCurrentFrame(int current, bool notify);
void updateBoundsSilent(int start, int end); void updateBoundsSilent(int start, int end);
@@ -76,6 +79,7 @@ private:
ValidatableSpinBox *m_startSpin; ValidatableSpinBox *m_startSpin;
ValidatableSpinBox *m_endSpin; ValidatableSpinBox *m_endSpin;
QSpinBox *m_currentSpin; QSpinBox *m_currentSpin;
QSlider *m_zoomSlider;
}; };
} // End namespace QmlDesigner. } // End namespace QmlDesigner.

View File

@@ -458,18 +458,6 @@ void CurveItem::setInterpolation(Keyframe::Interpolation interpolation)
emit curveChanged(id(), curve(true)); 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() void CurveItem::toggleUnified()
{ {
if (m_keyframes.empty()) if (m_keyframes.empty())

View File

@@ -125,8 +125,6 @@ public:
void setInterpolation(Keyframe::Interpolation interpolation); void setInterpolation(Keyframe::Interpolation interpolation);
void setDefaultInterpolation();
void toggleUnified(); void toggleUnified();
void connect(GraphicsScene *scene); void connect(GraphicsScene *scene);

View File

@@ -336,18 +336,6 @@ void GraphicsView::setInterpolation(Keyframe::Interpolation interpol)
viewport()->update(); 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() void GraphicsView::toggleUnified()
{ {
const auto selectedCurves = m_scene->selectedCurves(); const auto selectedCurves = m_scene->selectedCurves();
@@ -569,7 +557,10 @@ void GraphicsView::applyZoom(double x, double y, const QPoint &pivot)
} }
m_scene->doNotMoveItems(false); m_scene->doNotMoveItems(false);
this->update();
viewport()->update();
emit zoomChanged(m_zoomX, m_zoomY);
} }
void GraphicsView::drawGrid(QPainter *painter) void GraphicsView::drawGrid(QPainter *painter)

View File

@@ -49,6 +49,8 @@ class GraphicsView : public QGraphicsView
signals: signals:
void currentFrameChanged(int frame, bool notify); void currentFrameChanged(int frame, bool notify);
void zoomChanged(double x, double y);
public: public:
GraphicsView(CurveEditorModel *model, QWidget *parent = nullptr); GraphicsView(CurveEditorModel *model, QWidget *parent = nullptr);
@@ -112,8 +114,6 @@ public:
void setInterpolation(Keyframe::Interpolation interpol); void setInterpolation(Keyframe::Interpolation interpol);
void setDefaultInterpolation();
void toggleUnified(); void toggleUnified();
protected: protected:

View File

@@ -250,18 +250,6 @@ void KeyframeItem::setKeyframe(const Keyframe &keyframe)
setPos(m_transform.map(m_frame.position())); 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() void KeyframeItem::toggleUnified()
{ {
if (!m_left || !m_right) if (!m_left || !m_right)

View File

@@ -92,8 +92,6 @@ public:
void setKeyframe(const Keyframe &keyframe); void setKeyframe(const Keyframe &keyframe);
void setDefaultInterpolation();
void toggleUnified(); void toggleUnified();
void setActivated(bool active, HandleItem::Slot slot); void setActivated(bool active, HandleItem::Slot slot);

View File

@@ -154,15 +154,6 @@ void Keyframe::setPosition(const QPointF &pos)
m_position = 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) void Keyframe::setUnified(bool unified)
{ {
m_unified = unified; m_unified = unified;

View File

@@ -68,8 +68,6 @@ public:
Interpolation interpolation() const; Interpolation interpolation() const;
void setDefaultInterpolation();
void setUnified(bool unified); void setUnified(bool unified);
void setPosition(const QPointF &pos); void setPosition(const QPointF &pos);