From 304591d1d8a5ac7c87a85fb43137d2418eeb96f5 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 10 Sep 2012 16:04:19 +0300 Subject: [PATCH] Resizing of items works fine in all cases. --- src/domain/UBGraphicsDelegateFrame.cpp | 97 +++++++++++++++----------- src/domain/UBGraphicsDelegateFrame.h | 2 + 2 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 8c8e5dcb..b41e0376 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -325,11 +325,53 @@ QPointF UBGraphicsDelegateFrame::getFixedPointFromPos() fixedPoint = delegated()->sceneBoundingRect().bottomRight(); } } - else if (resizingBottomRight()) + } + return fixedPoint; +} + + +QSizeF UBGraphicsDelegateFrame::getResizeVector(qreal moveX, qreal moveY) +{ + qreal dPosX = 0; + qreal dPosY = 0; + + if (resizingTop()) + { + if (mMirrorX && mMirrorY) + dPosY = moveY; + else + dPosY = -moveY; + } + else if (resizingLeft()) + { + if (mMirrorX && mMirrorY) + dPosX = moveX; + else + dPosX = -moveX; + } + + else if (resizingRight()) + dPosX = (mMirrorX) ? -moveX : moveX; + else if (resizingBottom()) + dPosY = mMirrorY ? -moveY : moveY; + + return QSizeF(dPosX, dPosY); +} + +void UBGraphicsDelegateFrame::resizeDelegate(qreal moveX, qreal moveY) +{ + QPointF fixedPoint = getFixedPointFromPos(); + UBResizableGraphicsItem* resizableItem = dynamic_cast(delegated()); + if (resizableItem) + { + QSizeF originalSize = delegated()->boundingRect().size(); + resizableItem->resize(originalSize + getResizeVector(moveX, moveY)); + + if (resizingTop() || resizingLeft() || ((mMirrorX || mMirrorY) && resizingBottomRight())) { + delegated()->setPos(delegated()->pos()-getFixedPointFromPos()+fixedPoint); } } - return fixedPoint; } void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) @@ -523,54 +565,27 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } else if (mOperationMode == Resizing) { - QSizeF originalSize = delegated()->boundingRect().size(); - - mScaleX = 1; - mScaleY = 1; - if (!moving() && !rotating()) { - qreal dPosX = 0; - qreal dPosY = 0; - - QPointF fixedPoint = getFixedPointFromPos(); - - if (resizingTop()) - { - if (mMirrorX && mMirrorY) - dPosY = moveY; - else - dPosY = -moveY; - } - else if (resizingLeft()) + if (resizingBottomRight()) { if (mMirrorX && mMirrorY) - dPosX = moveX; + mCurrentTool = ResizeTop; else - dPosX = -moveX; - } - else if (resizingBottomRight()) - { - dPosX = moveX; - dPosY = moveY; - } - else if (resizingRight()) - dPosX = (mMirrorX) ? -moveX : moveX; - else if (resizingBottom()) - dPosY = mMirrorY ? -moveY : moveY; + mCurrentTool = ResizeBottom; - UBResizableGraphicsItem* resizableItem = dynamic_cast(delegated()); - if (resizableItem) - { - resizableItem->resize(originalSize.width() + dPosX, originalSize.height() + dPosY); - if (resizingTop() || resizingLeft() || ((mMirrorX || mMirrorY) && resizingBottomRight())) - { - QPointF newFixedPoint = getFixedPointFromPos();; + resizeDelegate(moveX, moveY); - delegated()->setPos(delegated()->pos()-newFixedPoint+fixedPoint); - } + if (mMirrorX && mMirrorY) + mCurrentTool = ResizeLeft; + else + mCurrentTool = ResizeRight; + resizeDelegate(moveX, moveY); + mCurrentTool = ResizeBottomRight; } + else + resizeDelegate(moveX, moveY); } } diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index 34aacda3..07166adf 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -38,6 +38,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); QPointF getFixedPointFromPos(); + QSizeF getResizeVector(qreal moveX, qreal moveY); + void resizeDelegate(qreal moveX, qreal moveY); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);