diff options
author | Knud Dollereder <knud.dollereder@qt.io> | 2019-08-13 16:07:53 +0200 |
---|---|---|
committer | Knud Dollereder <knud.dollereder@qt.io> | 2019-08-13 15:01:43 +0000 |
commit | d9537a9a8affc34326ca1a18c4ae9ecbd36f398c (patch) | |
tree | 742083d1d9ea18515757d2b41f4e0b2d654548c7 /src | |
parent | b6070995e055bc861ebed3cf647cf73bdaaf599e (diff) |
Improve scene to view fitting
Change-Id: Ib665c37db491d2af90f27a99f6b1c2d6f09b9df2
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src')
3 files changed, 17 insertions, 12 deletions
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp index b327e18c01..e1317265ff 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp @@ -85,13 +85,19 @@ int CurveItem::type() const QRectF CurveItem::boundingRect() const { + if (m_keyframes.empty()) + return QRectF(); + auto bbox = [](QRectF &bounds, const Keyframe &frame) { grow(bounds, frame.position()); - grow(bounds, frame.leftHandle()); - grow(bounds, frame.rightHandle()); + if (frame.hasLeftHandle()) + grow(bounds, frame.leftHandle()); + if (frame.hasRightHandle()) + grow(bounds, frame.rightHandle()); }; - QRectF bounds; + QPointF init = m_keyframes[0]->keyframe().position(); + QRectF bounds(init, init); for (auto *item : m_keyframes) bbox(bounds, item->keyframe()); @@ -213,11 +219,9 @@ std::vector<AnimationCurve> CurveItem::curves() const if (tmp.size() >= 2) out.push_back(AnimationCurve(tmp)); - out.push_back( - AnimationCurve( - current.data().value<QEasingCurve>(), - previous.position(), - current.position())); + out.push_back(AnimationCurve(current.data().value<QEasingCurve>(), + previous.position(), + current.position())); tmp.clear(); tmp.push_back(current); diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp index cf88397a46..14a7399bfe 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp @@ -142,7 +142,7 @@ void GraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) for (auto *item : itemList) { if (auto *curveItem = qgraphicsitem_cast<CurveItem *>(item)) { - // CurveItems might becom invalid after a keyframe-drag operation. + // CurveItems might become invalid after a keyframe-drag operation. curveItem->restore(); if (curveItem->contains(mouseEvent->scenePos())) diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp index bfa836137f..94b53a3ea5 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp @@ -378,13 +378,16 @@ void GraphicsView::applyZoom(double x, double y, const QPoint &pivot) double minTime = minimumTime(); double maxTime = maximumTime(); + double minValue = minimumValue(); + double maxValue = maximumValue(); + QRectF canvas = canvasRect(); double xZoomedOut = canvas.width() / (maxTime - minTime); double xZoomedIn = m_style.zoomInWidth; double scaleX = lerp(clamp(m_zoomX, 0.0, 1.0), xZoomedOut, xZoomedIn); - double yZoomedOut = canvas.height() / maximumValue(); + double yZoomedOut = canvas.height() / (maxValue - minValue); double yZoomedIn = m_style.zoomInHeight; double scaleY = lerp(clamp(m_zoomY, 0.0, 1.0), -yZoomedOut, -yZoomedIn); @@ -480,8 +483,6 @@ void GraphicsView::drawExtremaY(QPainter *painter, const QRectF &rect) drawHorizontalLine(mapValueToY(m_scene.minimumValue())); drawHorizontalLine(mapValueToY(m_scene.maximumValue())); - drawHorizontalLine(mapValueToY(0.0)); - painter->restore(); } |