diff options
author | Knud Dollereder <knud.dollereder@qt.io> | 2020-02-21 15:28:31 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2020-03-17 17:19:14 +0000 |
commit | 5b000d17cb2f42891db7bd8c9c857866245eddd3 (patch) | |
tree | 97b2a33c6be95de50028e24e2d2f0e85ac262055 /src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp | |
parent | 0f60f120d2e24b9912b43b5ba4859adcd5a1a803 (diff) |
QmlDesigner: Add the ability to modify the animation rangev4.12.0-beta2
Add the ability to modify the animation range from the curve editor
Fix a synchronization issue between timeline and curve editor when
the animation contains pinned curves
Change-Id: I89dda234063259f41d662749d696f5fc8a04f988
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp')
-rw-r--r-- | src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp index 51e4b35c88..b51d916fb0 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp @@ -231,6 +231,16 @@ void GraphicsView::scrollContent(double x, double y) void GraphicsView::reset(const std::vector<CurveItem *> &items) { + m_scene.clear(); + for (auto *item : items) + m_scene.addCurveItem(item); + + applyZoom(m_zoomX, m_zoomY); + viewport()->update(); +} + +void GraphicsView::updateSelection(const std::vector<CurveItem *> &items) +{ const std::vector<CurveItem *> pinnedItems = m_scene.takePinnedItems(); auto notPinned = [pinnedItems](CurveItem *item) { for (auto *pinned : pinnedItems) { @@ -541,6 +551,38 @@ void GraphicsView::drawExtremaY(QPainter *painter, const QRectF &rect) } #endif +void GraphicsView::drawRangeBar(QPainter *painter, const QRectF &rect) +{ + QFontMetrics fm(painter->font()); + QRectF labelRect = fm.boundingRect(QString("0")); + labelRect.moveCenter(rect.center()); + + qreal bTick = rect.bottom() - 2; + qreal tTick = labelRect.bottom() + 2; + QRectF activeRect = QRectF(QPointF(mapTimeToX(m_model->minimumTime()), tTick), + QPointF(mapTimeToX(m_model->maximumTime()), bTick)); + + QColor color = Qt::white; + color.setAlpha(30); + + painter->fillRect(activeRect, color); + + QColor handleColor(Qt::green); + painter->setBrush(handleColor); + painter->setPen(handleColor); + + const qreal radius = 5.; + QRectF minHandle = rangeMinHandle(rect); + painter->drawRoundedRect(minHandle, radius, radius); + minHandle.setLeft(minHandle.center().x()); + painter->fillRect(minHandle, Qt::green); + + QRectF maxHandle = rangeMaxHandle(rect); + painter->drawRoundedRect(maxHandle, radius, radius); + maxHandle.setRight(maxHandle.center().x()); + painter->fillRect(maxHandle, Qt::green); +} + void GraphicsView::drawTimeScale(QPainter *painter, const QRectF &rect) { painter->save(); @@ -565,6 +607,8 @@ void GraphicsView::drawTimeScale(QPainter *painter, const QRectF &rect) for (double i = minimumTime(); i <= maximumTime(); i += timeIncrement) paintLabeledTick(i); + drawRangeBar(painter, rect); + painter->restore(); } @@ -619,4 +663,28 @@ double GraphicsView::timeLabelInterval(QPainter *painter, double maxTime) return deltaTime; } +QRectF GraphicsView::rangeMinHandle(const QRectF &rect) +{ + QRectF labelRect = fontMetrics().boundingRect(QString("0")); + labelRect.moveCenter(rect.center()); + + qreal top = rect.bottom() - 2; + qreal bottom = labelRect.bottom() + 2; + QSize size(10, top - bottom); + + int leftHandleLeft = mapTimeToX(m_model->minimumTime()) - size.width(); + return QRectF(QPointF(leftHandleLeft, bottom), size); +} + +QRectF GraphicsView::rangeMaxHandle(const QRectF &rect) +{ + QRectF labelRect = fontMetrics().boundingRect(QString("0")); + labelRect.moveCenter(rect.center()); + + qreal bottom = rect.bottom() - 2; + qreal top = labelRect.bottom() + 2; + + return QRectF(QPointF(mapTimeToX(m_model->maximumTime()), bottom), QSize(10, top - bottom)); +} + } // End namespace DesignTools. |