From a4bff368fd05fe609a1f1ec146b73fa8b167b817 Mon Sep 17 00:00:00 2001 From: Knud Dollereder Date: Thu, 24 Oct 2019 17:09:22 +0200 Subject: [PATCH] Display the current frame in a dedicated control Enable immediate dragging of the playhead after clicking into the time-scale Rename "Curve Picker" to "Easing Curve Editor" and "Curve Editor" to "Animation Curve Editor" Change-Id: I0085a26d0ea510286586d89c6cddb9bbe720e49e Reviewed-by: Tim Jenssen --- .../components/curveeditor/curveeditor.cpp | 13 ++++++++++++- .../components/curveeditor/detail/graphicsview.cpp | 6 +++++- .../components/curveeditor/detail/graphicsview.h | 5 ++++- .../components/curveeditor/detail/playhead.cpp | 5 +++++ .../components/curveeditor/detail/playhead.h | 2 ++ .../components/timelineeditor/timelinetoolbar.cpp | 6 +++--- 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp b/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp index d06ea3c4957..72bdf4be135 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp @@ -113,9 +113,20 @@ QToolBar *CurveEditor::createToolBar() durationWidget->setLayout(durationBox); bar->addWidget(durationWidget); + auto *cfspin = new QSpinBox; + cfspin->setMinimum(0); + cfspin->setMaximum(std::numeric_limits::max()); + + auto intSignal = static_cast(&QSpinBox::valueChanged); + connect(cfspin, intSignal, [this](int val) { m_view->setCurrentFrame(val, false); }); + connect(m_view, &GraphicsView::notifyFrameChanged, [cfspin](int val) { + QSignalBlocker blocker(cfspin); + cfspin->setValue(val); + }); + auto *positionBox = new QHBoxLayout; positionBox->addWidget(new QLabel(tr("Current Frame"))); - positionBox->addWidget(new QSpinBox); + positionBox->addWidget(cfspin); auto *positionWidget = new QWidget; positionWidget->setLayout(positionBox); bar->addWidget(positionWidget); diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp index 7a711923ccd..f225128a01b 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp @@ -184,11 +184,14 @@ void GraphicsView::setZoomY(double zoom, const QPoint &pivot) viewport()->update(); } -void GraphicsView::setCurrentFrame(int frame) +void GraphicsView::setCurrentFrame(int frame, bool notify) { int clampedFrame = clamp(frame, m_model->minimumTime(), m_model->maximumTime()); m_playhead.moveToFrame(clampedFrame, this); viewport()->update(); + + if (notify) + notifyFrameChanged(frame); } void GraphicsView::scrollContent(double x, double y) @@ -251,6 +254,7 @@ void GraphicsView::mousePressEvent(QMouseEvent *event) QPointF pos = mapToScene(event->pos()); if (timeScaleRect().contains(pos)) { setCurrentFrame(std::round(mapXtoTime(pos.x()))); + m_playhead.setMoving(true); event->accept(); return; } diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.h b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.h index af138429bf2..d7c2f14da00 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.h +++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.h @@ -45,6 +45,9 @@ class GraphicsView : public QGraphicsView friend class Playhead; +signals: + void notifyFrameChanged(int frame); + public: GraphicsView(CurveEditorModel *model, QWidget *parent = nullptr); @@ -94,7 +97,7 @@ public: void setZoomY(double zoom, const QPoint &pivot = QPoint()); - void setCurrentFrame(int frame); + void setCurrentFrame(int frame, bool notify = true); void scrollContent(double x, double y); diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/playhead.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/playhead.cpp index e2e6d212746..7b25bbb9af5 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/playhead.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/playhead.cpp @@ -56,6 +56,11 @@ int Playhead::currentFrame() const return m_frame; } +void Playhead::setMoving(bool moving) +{ + m_moving = moving; +} + void Playhead::moveToFrame(int frame, GraphicsView *view) { m_frame = frame; diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/playhead.h b/src/plugins/qmldesigner/components/curveeditor/detail/playhead.h index 3a785624bdb..9f6295c34a7 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/playhead.h +++ b/src/plugins/qmldesigner/components/curveeditor/detail/playhead.h @@ -45,6 +45,8 @@ public: void paint(QPainter *painter, GraphicsView *view) const; + void setMoving(bool moving); + void moveToFrame(int frame, GraphicsView *view); void resize(GraphicsView *view); diff --git a/src/plugins/qmldesigner/components/timelineeditor/timelinetoolbar.cpp b/src/plugins/qmldesigner/components/timelineeditor/timelinetoolbar.cpp index 8ad8499d174..a233e19aadf 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/timelinetoolbar.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/timelinetoolbar.cpp @@ -272,7 +272,7 @@ void TimelineToolBar::createLeftControls() auto *curveEditorAction = createAction(TimelineConstants::C_CURVE_EDITOR, TimelineIcons::CURVE_EDITORDIALOG.icon(), - tr("Curve Editor"), + tr("Animation Curve Editor"), QKeySequence(Qt::Key_C)); connect(curveEditorAction, @@ -396,10 +396,10 @@ void TimelineToolBar::createCenterControls() auto *curvePicker = createAction(TimelineConstants::C_CURVE_PICKER, TimelineIcons::CURVE_EDITOR.icon(), - tr("Curve Picker"), + tr("Easing Curve Editor"), QKeySequence(Qt::Key_C)); - curvePicker->setObjectName("Curve Picker"); + curvePicker->setObjectName("Easing Curve Editor"); connect(curvePicker, &QAction::triggered, this, &TimelineToolBar::openEasingCurveEditor); addAction(curvePicker);