From 9888b99a017332fe4c1308adb11bbcf4dfd67028 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Wed, 3 Oct 2012 14:55:06 +0300 Subject: [PATCH] Fixed items scaling. --- src/domain/UBGraphicsDelegateFrame.cpp | 43 +++++++++++++++++++++++--- src/domain/UBGraphicsDelegateFrame.h | 3 ++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 38f96dc0..71351090 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -49,6 +49,8 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega , mTotalTranslateX(0) , mTotalTranslateY(0) , mOperationMode(Scaling) + , mFlippedX(false) + , mFlippedY(false) , mMirrorX(false) , mMirrorY(false) { @@ -379,6 +381,12 @@ QSizeF UBGraphicsDelegateFrame::resizeDelegate(qreal moveX, qreal moveY) return incVector; } + +void UBGraphicsDelegateFrame::scaleByPos(qreal scaleX, qreal scaleY) +{ + +} + void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (None == mCurrentTool) @@ -451,6 +459,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) scaleX = -2*mFrameWidth/width; }else{ scaleX = -1; + mFlippedX = !mFlippedX; } } mScaleX = scaleX; @@ -480,6 +489,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) scaleY = -2*mFrameWidth/width; }else{ scaleY = -1; + mFlippedY = !mFlippedY; } } mScaleY = scaleY; @@ -543,15 +553,38 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) QPointF ref; // we just detects coordinates of corner before and after scaling and then moves object at diff between them. - if (resizingBottomRight() && mMirrorX) + if (resizingBottomRight() && (mMirrorX || mMirrorY)) { - mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); - mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); + if (mFlippedX && !mMirrorX && mFlippedY)// && !mMirrorY) + { + mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); + mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); + } + else if ((mFlippedX || mMirrorX) && (mFlippedY || mMirrorY)) + { + mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); + mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); + } + else if (mFlippedX || mMirrorX) + { + mTranslateX += mInitialTransform.map(delegated()->boundingRect().topRight()).x() - tr.map(delegated()->boundingRect().topRight()).x(); + mTranslateY += mInitialTransform.map(delegated()->boundingRect().topRight()).y() - tr.map(delegated()->boundingRect().topRight()).y(); + } + else if (mFlippedY || mMirrorY) + { + mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); + mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); + } + else + { + mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); + mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); + } } else { - mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x(); - mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); + mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x(); + mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); } } else if (resizingTop() || resizingLeft()) diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index d3034711..e171358b 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -40,6 +40,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject QPointF getFixedPointFromPos(); QSizeF getResizeVector(qreal moveX, qreal moveY); QSizeF resizeDelegate(qreal moveX, qreal moveY); + void scaleByPos(qreal scaleX, qreal scaleY); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); @@ -124,6 +125,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject OperationMode mOperationMode; QGraphicsItem* delegated(); + bool mFlippedX; + bool mFlippedY; bool mMirrorX; bool mMirrorY; bool mResizing;