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)
{
lastRect = rect().toRect();
lastPos = event->screenPos();
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
{
mResizing1 = true;
event->accept();
}
else if (resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
else
if (resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
{
mResizing2 = true;
event->accept();
}
else if(rotateRect().contains(event->pos()))
else
if(rotateRect().contains(event->pos()))
{
mRotating = true;
event->accept();
@ -596,72 +601,69 @@ void UBGraphicsTriangle::mousePressEvent(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)
{
QGraphicsItem::mouseMoveEvent(event);
}
else
{
//-----------------------------------------------//
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)
{
setRect(QRectF(
rect().topLeft(),
QSizeF(rect().width() + delta.x(),
rect().height())),
mOrientation);
int deltaX = currPos.x() - lastPos.x();
if (lastRect.width() + deltaX < sMinWidth)
deltaX = sMinWidth - lastRect.width();
setRect(QRectF(lastRect.left(), lastRect.top(),
lastRect.width() + deltaX, lastRect.height()), mOrientation);
}
else
{
setRect(QRectF(
rect().left() + delta.x(),
rect().top(),
rect().width() - delta.x(),
rect().height()),
mOrientation
);
int deltaX = lastPos.x() - currPos.x();
if (lastRect.width() + deltaX < sMinWidth)
deltaX = sMinWidth - lastRect.width();
setRect(QRectF(lastRect.left() - deltaX, lastRect.top(),
lastRect.width() + deltaX, lastRect.height()), mOrientation);
}
}
//-----------------------------------------------//
if (mResizing2)
{
QPointF delta = event->pos() - event->lastPos();
if (mOrientation == BottomRight || mOrientation == BottomLeft)
{
if (rect().height() - delta.y() < (qreal)sMinHeight)
delta.setY((qreal)sMinHeight - rect().height());
int deltaY = lastPos.y() - currPos.y();
if (lastRect.height() + deltaY < sMinHeight)
deltaY = sMinHeight - lastRect.height();
setRect(QRectF(lastRect.left(), lastRect.top() - deltaY,
lastRect.width(), lastRect.height() + deltaY), mOrientation);
}
else
{
if (rect().height() + delta.y() < (qreal)sMinHeight)
delta.setY((qreal)sMinHeight - rect().height());
int deltaY = currPos.y() - lastPos.y();
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)
{
QLineF currentLine(rotationCenter(), event->pos());
@ -669,6 +671,8 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
rotateAroundCenter(currentLine.angleTo(lastLine));
}
//-----------------------------------------------//
event->accept();
}
}

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

Loading…
Cancel
Save