Merge fix for resizing of items from aleksei_kanash_dev.

preferencesAboutTextFull
Aleksei Kanash 12 years ago
commit 3d3a040bbc
  1. 3
      src/board/UBBoardView.cpp
  2. 63
      src/domain/UBGraphicsDelegateFrame.cpp
  3. 4
      src/domain/UBGraphicsDelegateFrame.h

@ -749,9 +749,6 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event)
void UBBoardView::handleItemMouseMove(QMouseEvent *event) void UBBoardView::handleItemMouseMove(QMouseEvent *event)
{ {
if (!movingItem)
return;
// determine item to move (maybee we need to move group of item or his parent. // determine item to move (maybee we need to move group of item or his parent.
movingItem = determineItemToMove(movingItem); movingItem = determineItemToMove(movingItem);

@ -224,11 +224,13 @@ void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event)
mAngleOffset = 0; mAngleOffset = 0;
mInitialTransform = buildTransform(); mInitialTransform = buildTransform();
mOriginalSize = delegated()->boundingRect().size();
mCurrentTool = toolFromPos(event->pos()); mCurrentTool = toolFromPos(event->pos());
setCursorFromAngle(QString::number((int)mAngle % 360)); setCursorFromAngle(QString::number((int)mAngle % 360));
event->accept(); event->accept();
if (moving())
prepareFramesToMove(getLinkedFrames()); prepareFramesToMove(getLinkedFrames());
} }
@ -358,20 +360,25 @@ QSizeF UBGraphicsDelegateFrame::getResizeVector(qreal moveX, qreal moveY)
return QSizeF(dPosX, dPosY); return QSizeF(dPosX, dPosY);
} }
void UBGraphicsDelegateFrame::resizeDelegate(qreal moveX, qreal moveY) QSizeF UBGraphicsDelegateFrame::resizeDelegate(qreal moveX, qreal moveY)
{ {
QPointF fixedPoint = getFixedPointFromPos(); QSizeF incVector;
mFixedPoint = getFixedPointFromPos();
UBResizableGraphicsItem* resizableItem = dynamic_cast<UBResizableGraphicsItem*>(delegated()); UBResizableGraphicsItem* resizableItem = dynamic_cast<UBResizableGraphicsItem*>(delegated());
if (resizableItem) if (resizableItem)
{ {
QSizeF originalSize = delegated()->boundingRect().size(); incVector = getResizeVector(moveX, moveY);
resizableItem->resize(originalSize + getResizeVector(moveX, moveY)); resizableItem->resize(mOriginalSize + incVector);
if (resizingTop() || resizingLeft() || ((mMirrorX || mMirrorY) && resizingBottomRight())) if (resizingTop() || resizingLeft() || ((mMirrorX || mMirrorY) && resizingBottomRight()))
{ {
delegated()->setPos(delegated()->pos()-getFixedPointFromPos()+fixedPoint); QPointF pos1 = getFixedPointFromPos();
delegated()->setPos(delegated()->pos()-pos1+mFixedPoint);
} }
} }
return incVector;
} }
void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
@ -379,17 +386,14 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (None == mCurrentTool) if (None == mCurrentTool)
return; return;
QLineF move; QLineF move = QLineF(mStartingPoint, event->scenePos());
if(rotating() || moving() || mOperationMode == Scaling)
move = QLineF(mStartingPoint, event->scenePos());
else
move = QLineF(event->lastScenePos(), event->scenePos());
qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180);
qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180);
qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal width = delegated()->boundingRect().width() * mTotalScaleX;
qreal height = delegated()->boundingRect().height() * mTotalScaleY; qreal height = delegated()->boundingRect().height() * mTotalScaleY;
if (mOperationMode == Scaling)
{
if(!rotating()) if(!rotating())
{ {
mTranslateX = moveX; mTranslateX = moveX;
@ -491,6 +495,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
} }
} }
} }
}
if (rotating()) if (rotating())
{ {
@ -531,6 +536,8 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
moveLinkedItems(move); moveLinkedItems(move);
} }
if (mOperationMode == Scaling || moving() || rotating())
{
QTransform tr = buildTransform(); QTransform tr = buildTransform();
if (resizingRight() || resizingBottom() || resizingBottomRight()) if (resizingRight() || resizingBottom() || resizingBottomRight())
@ -556,39 +563,48 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
mTranslateX += fixedPoint.x() - bottomRight.x(); mTranslateX += fixedPoint.x() - bottomRight.x();
mTranslateY += fixedPoint.y() - bottomRight.y(); mTranslateY += fixedPoint.y() - bottomRight.y();
} }
else if (moving() || rotating())
if (mOperationMode == Scaling || moving() || rotating())
{
tr = buildTransform();
delegated()->setTransform(tr); delegated()->setTransform(tr);
} }
else if (mOperationMode == Resizing) else // resizing/resizing horizontally
{
if (!moving() && !rotating())
{ {
if (resizingBottomRight()) if (resizingBottomRight())
{ {
static QSizeF incV = QSizeF();
static QSizeF incH = QSizeF();
if (mMirrorX && mMirrorY) if (mMirrorX && mMirrorY)
mCurrentTool = ResizeTop; mCurrentTool = ResizeTop;
else else
mCurrentTool = ResizeBottom; mCurrentTool = ResizeBottom;
resizeDelegate(moveX, moveY); mOriginalSize -= incH;
incV = resizeDelegate(moveX, moveY);
mOriginalSize += incV;
if (mMirrorX && mMirrorY) if (mMirrorX && mMirrorY)
mCurrentTool = ResizeLeft; mCurrentTool = ResizeLeft;
else else
mCurrentTool = ResizeRight; mCurrentTool = ResizeRight;
resizeDelegate(moveX, moveY); move = QLineF(event->lastScenePos(), event->scenePos());
moveX = move.length() * cos((move.angle() - mAngle) * PI / 180);
moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180);
mFixedPoint = getFixedPointFromPos();
incH = resizeDelegate(moveX, moveY);
mOriginalSize -= incV;
mOriginalSize += incH;
mCurrentTool = ResizeBottomRight; mCurrentTool = ResizeBottomRight;
} }
else else
resizeDelegate(moveX, moveY); resizeDelegate(moveX, moveY);
} }
}
event->accept(); event->accept();
} }
@ -689,6 +705,7 @@ void UBGraphicsDelegateFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
event->accept(); event->accept();
mCurrentTool = None; mCurrentTool = None;
QGraphicsRectItem::mouseReleaseEvent(event); QGraphicsRectItem::mouseReleaseEvent(event);
// Show the buttons // Show the buttons

@ -39,7 +39,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
QPointF getFixedPointFromPos(); QPointF getFixedPointFromPos();
QSizeF getResizeVector(qreal moveX, qreal moveY); QSizeF getResizeVector(qreal moveX, qreal moveY);
void resizeDelegate(qreal moveX, qreal moveY); QSizeF resizeDelegate(qreal moveX, qreal moveY);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
@ -105,6 +105,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
QPointF mStartingPoint; QPointF mStartingPoint;
QTransform mInitialTransform; QTransform mInitialTransform;
QSizeF mOriginalSize;
QPointF mFixedPoint;
QGraphicsSvgItem* mBottomRightResizeGripSvgItem; QGraphicsSvgItem* mBottomRightResizeGripSvgItem;
QGraphicsSvgItem* mBottomResizeGripSvgItem; QGraphicsSvgItem* mBottomResizeGripSvgItem;

Loading…
Cancel
Save