Fixed (returned back) mouse move events handling for clean scene.

Reworked resizing of items on board. Still have troubles with resizing at BottomRight resizer.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent d469951de1
commit c57beb74ca
  1. 3
      src/board/UBBoardView.cpp
  2. 57
      src/domain/UBGraphicsDelegateFrame.cpp
  3. 4
      src/domain/UBGraphicsDelegateFrame.h

@ -749,9 +749,6 @@ void UBBoardView::handleItemMousePress(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.
movingItem = determineItemToMove(movingItem);

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

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

Loading…
Cancel
Save