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. 287
      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,12 +224,14 @@ 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();
prepareFramesToMove(getLinkedFrames());
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,113 +386,111 @@ 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(!rotating())
if (mOperationMode == Scaling)
{
mTranslateX = moveX;
// Perform the resize
if (resizingBottomRight())
if(!rotating())
{
// -----------------------------------------------------
// ! We want to keep the aspect ratio with this resize !
// -----------------------------------------------------
qreal scaleX;
qreal scaleY;
if(!mMirrorX){
scaleX = (width + moveX) / width;
}else{
scaleX = (width - moveX) / width;
}
if(!mMirrorY){
scaleY = (height + moveY) / height;
}else{
scaleY = (height - moveY) / height;
}
mTranslateX = moveX;
// Perform the resize
if (resizingBottomRight())
{
// -----------------------------------------------------
// ! We want to keep the aspect ratio with this resize !
// -----------------------------------------------------
qreal scaleX;
qreal scaleY;
qreal scaleFactor = (scaleX + scaleY) / 2;
if(!mMirrorX){
scaleX = (width + moveX) / width;
}else{
scaleX = (width - moveX) / width;
}
// Do not allow resizing of image size under frame size
if (canResizeBottomRight(width, height, scaleFactor))
{
if (mRespectRatio)
{
mScaleX = scaleFactor;
mScaleY = scaleFactor;
if(!mMirrorY){
scaleY = (height + moveY) / height;
}else{
scaleY = (height - moveY) / height;
}
else
qreal scaleFactor = (scaleX + scaleY) / 2;
// Do not allow resizing of image size under frame size
if (canResizeBottomRight(width, height, scaleFactor))
{
mScaleX = scaleX;
mScaleY = scaleY;
}
}
}else if (resizingLeft() || resizingRight())
{
if(width != 0){
qreal scaleX = 0.0;
if(resizingLeft()){
scaleX = (width - moveX) / width;
}else if(resizingRight()){
scaleX = (width + moveX) / width;
}
if(mDelegate->isFlippable() && qAbs(scaleX) != 0){
if((qAbs(width * scaleX)) < 2*mFrameWidth){
bool negative = (scaleX < 0)?true:false;
if(negative){
if(mMirrorX)
scaleX = 2*mFrameWidth/width;
else
scaleX = -2*mFrameWidth/width;
}else{
scaleX = -1;
}
if (mRespectRatio)
{
mScaleX = scaleFactor;
mScaleY = scaleFactor;
}
mScaleX = scaleX;
}else if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth){
mScaleX = scaleX;
if(resizingLeft()){
mTranslateX = moveX;
else
{
mScaleX = scaleX;
mScaleY = scaleY;
}
}
}
}else if(resizingTop() || resizingBottom()){
if(height != 0){
qreal scaleY = 0.0;
if(resizingTop()){
scaleY = (height - moveY) / height;
}else if(resizingBottom()){
scaleY = (height + moveY) / height;
}
if(mDelegate->isFlippable() && qAbs(scaleY) != 0){
if((qAbs(height * scaleY)) < 2*mFrameWidth){
bool negative = (scaleY < 0)?true:false;
if(negative){
if(mMirrorY)
scaleY = 2*mFrameWidth/width;
else
scaleY = -2*mFrameWidth/width;
}else{
scaleY = -1;
}else if (resizingLeft() || resizingRight())
{
if(width != 0){
qreal scaleX = 0.0;
if(resizingLeft()){
scaleX = (width - moveX) / width;
}else if(resizingRight()){
scaleX = (width + moveX) / width;
}
if(mDelegate->isFlippable() && qAbs(scaleX) != 0){
if((qAbs(width * scaleX)) < 2*mFrameWidth){
bool negative = (scaleX < 0)?true:false;
if(negative){
if(mMirrorX)
scaleX = 2*mFrameWidth/width;
else
scaleX = -2*mFrameWidth/width;
}else{
scaleX = -1;
}
}
mScaleX = scaleX;
}else if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth){
mScaleX = scaleX;
if(resizingLeft()){
mTranslateX = moveX;
}
}
mScaleY = scaleY;
}else if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth)
{
mScaleY = scaleY;
}
}else if(resizingTop() || resizingBottom()){
if(height != 0){
qreal scaleY = 0.0;
if(resizingTop()){
mTranslateY = moveY;
scaleY = (height - moveY) / height;
}else if(resizingBottom()){
scaleY = (height + moveY) / height;
}
if(mDelegate->isFlippable() && qAbs(scaleY) != 0){
if((qAbs(height * scaleY)) < 2*mFrameWidth){
bool negative = (scaleY < 0)?true:false;
if(negative){
if(mMirrorY)
scaleY = 2*mFrameWidth/width;
else
scaleY = -2*mFrameWidth/width;
}else{
scaleY = -1;
}
}
mScaleY = scaleY;
}else if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth)
{
mScaleY = scaleY;
if(resizingTop()){
mTranslateY = moveY;
}
}
}
}
@ -531,64 +536,69 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
moveLinkedItems(move);
}
QTransform tr = buildTransform();
if (resizingRight() || resizingBottom() || resizingBottomRight())
if (mOperationMode == Scaling || moving() || rotating())
{
QPointF ref;
QTransform tr = buildTransform();
// we just detects coordinates of corner before and after scaling and then moves object at diff between them.
if (resizingBottomRight() && mMirrorX)
if (resizingRight() || resizingBottom() || resizingBottomRight())
{
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();
QPointF ref;
// we just detects coordinates of corner before and after scaling and then moves object at diff between them.
if (resizingBottomRight() && mMirrorX)
{
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();
}
}
else
else if (resizingTop() || resizingLeft())
{
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();
QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight());
QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight());
mTranslateX += fixedPoint.x() - bottomRight.x();
mTranslateY += fixedPoint.y() - bottomRight.y();
}
else if (moving() || rotating())
delegated()->setTransform(tr);
}
else if (resizingTop() || resizingLeft())
else // resizing/resizing horizontally
{
QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight());
QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight());
mTranslateX += fixedPoint.x() - bottomRight.x();
mTranslateY += fixedPoint.y() - bottomRight.y();
}
if (mOperationMode == Scaling || moving() || rotating())
{
tr = buildTransform();
delegated()->setTransform(tr);
}
else if (mOperationMode == Resizing)
{
if (!moving() && !rotating())
if (resizingBottomRight())
{
if (resizingBottomRight())
{
if (mMirrorX && mMirrorY)
mCurrentTool = ResizeTop;
else
mCurrentTool = ResizeBottom;
static QSizeF incV = QSizeF();
static QSizeF incH = QSizeF();
resizeDelegate(moveX, moveY);
if (mMirrorX && mMirrorY)
mCurrentTool = ResizeTop;
else
mCurrentTool = ResizeBottom;
if (mMirrorX && mMirrorY)
mCurrentTool = ResizeLeft;
else
mCurrentTool = ResizeRight;
mOriginalSize -= incH;
resizeDelegate(moveX, moveY);
mCurrentTool = ResizeBottomRight;
}
incV = resizeDelegate(moveX, moveY);
mOriginalSize += incV;
if (mMirrorX && mMirrorY)
mCurrentTool = ResizeLeft;
else
resizeDelegate(moveX, moveY);
mCurrentTool = ResizeRight;
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