Triangle resizing bug fix

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent bba6631b63
commit de2fb68f0b
  1. 92
      src/tools/UBGraphicsTriangle.cpp
  2. 2
      src/tools/UBGraphicsTriangle.h

@ -567,17 +567,22 @@ QCursor UBGraphicsTriangle::flipCursor() const
void UBGraphicsTriangle::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsTriangle::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
lastRect = rect().toRect();
lastPos = event->screenPos();
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill)) if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
{ {
mResizing1 = true; mResizing1 = true;
event->accept(); event->accept();
} }
else if (resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill)) else
if (resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
{ {
mResizing2 = true; mResizing2 = true;
event->accept(); event->accept();
} }
else if(rotateRect().contains(event->pos())) else
if(rotateRect().contains(event->pos()))
{ {
mRotating = true; mRotating = true;
event->accept(); event->accept();
@ -596,72 +601,69 @@ void UBGraphicsTriangle::mousePressEvent(QGraphicsSceneMouseEvent *event)
void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
QPoint currPos = event->screenPos();
// qDebug() << QString(" X: %1 ").arg(currPos.x());
// qDebug() << QString(" Y: %1 ").arg(currPos.y());
if (!mResizing1 && !mResizing2 && !mRotating) if (!mResizing1 && !mResizing2 && !mRotating)
{ {
QGraphicsItem::mouseMoveEvent(event); QGraphicsItem::mouseMoveEvent(event);
} }
else else
{ {
//-----------------------------------------------//
if (mResizing1) if (mResizing1)
{ {
QPointF delta = event->pos() - event->lastPos();
if (mOrientation == TopLeft || mOrientation == BottomLeft)
{
if (rect().width() + delta.x() < (qreal)sMinWidth)
delta.setX((qreal)sMinWidth - rect().width());
}
else
{
if (rect().width() - delta.x() < (qreal)sMinWidth)
delta.setX((qreal)sMinWidth - rect().width());
}
if (mOrientation == TopLeft || mOrientation == BottomLeft) if (mOrientation == TopLeft || mOrientation == BottomLeft)
{ {
setRect(QRectF( int deltaX = currPos.x() - lastPos.x();
rect().topLeft(), if (lastRect.width() + deltaX < sMinWidth)
QSizeF(rect().width() + delta.x(), deltaX = sMinWidth - lastRect.width();
rect().height())),
mOrientation); setRect(QRectF(lastRect.left(), lastRect.top(),
lastRect.width() + deltaX, lastRect.height()), mOrientation);
} }
else else
{ {
setRect(QRectF( int deltaX = lastPos.x() - currPos.x();
rect().left() + delta.x(), if (lastRect.width() + deltaX < sMinWidth)
rect().top(), deltaX = sMinWidth - lastRect.width();
rect().width() - delta.x(),
rect().height()), setRect(QRectF(lastRect.left() - deltaX, lastRect.top(),
mOrientation lastRect.width() + deltaX, lastRect.height()), mOrientation);
);
} }
} }
//-----------------------------------------------//
if (mResizing2) if (mResizing2)
{ {
QPointF delta = event->pos() - event->lastPos();
if (mOrientation == BottomRight || mOrientation == BottomLeft) if (mOrientation == BottomRight || mOrientation == BottomLeft)
{ {
if (rect().height() - delta.y() < (qreal)sMinHeight) int deltaY = lastPos.y() - currPos.y();
delta.setY((qreal)sMinHeight - rect().height()); if (lastRect.height() + deltaY < sMinHeight)
deltaY = sMinHeight - lastRect.height();
setRect(QRectF(lastRect.left(), lastRect.top() - deltaY,
lastRect.width(), lastRect.height() + deltaY), mOrientation);
} }
else else
{ {
if (rect().height() + delta.y() < (qreal)sMinHeight) int deltaY = currPos.y() - lastPos.y();
delta.setY((qreal)sMinHeight - rect().height()); if (lastRect.height() + deltaY < sMinHeight)
deltaY = sMinHeight - lastRect.height();
setRect(QRectF(lastRect.left(), lastRect.top(),
lastRect.width(), lastRect.height() + deltaY), mOrientation);
} }
if (mOrientation == BottomRight || mOrientation == BottomLeft)
setRect(QRectF(
rect().left(),
rect().top() + delta.y(),
rect().width(),
rect().height() - delta.y()),
mOrientation);
else
setRect(QRectF(
rect().left(),
rect().top(),
rect().width(),
rect().height() + delta.y()),
mOrientation);
} }
//-----------------------------------------------//
if (mRotating) if (mRotating)
{ {
QLineF currentLine(rotationCenter(), event->pos()); QLineF currentLine(rotationCenter(), event->pos());
@ -669,6 +671,8 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
rotateAroundCenter(currentLine.angleTo(lastLine)); rotateAroundCenter(currentLine.angleTo(lastLine));
} }
//-----------------------------------------------//
event->accept(); event->accept();
} }
} }

@ -113,6 +113,8 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
bool mResizing1; bool mResizing1;
bool mResizing2; bool mResizing2;
bool mRotating; bool mRotating;
QRect lastRect;
QPoint lastPos;
QGraphicsSvgItem* mHFlipSvgItem; QGraphicsSvgItem* mHFlipSvgItem;
QGraphicsSvgItem* mVFlipSvgItem; QGraphicsSvgItem* mVFlipSvgItem;

Loading…
Cancel
Save