Graphics Triangle Tool

preferencesAboutTextFull
Anatoly Mihalchenko 14 years ago
parent 331a82ff16
commit 2491e7e33d
  1. 427
      src/tools/UBGraphicsTriangle.cpp
  2. 17
      src/tools/UBGraphicsTriangle.h

@ -40,9 +40,35 @@ UBGraphicsTriangle::UBGraphicsTriangle()
mRotateSvgItem->setVisible(false); mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
//updateResizeCursor(); updateResizeCursor();
} }
void UBGraphicsTriangle::updateResizeCursor()
{
QPixmap pix(":/images/cursors/resize.png");
QTransform itemTransform = sceneTransform();
QRectF itemRect = boundingRect();
QPointF topLeft = itemTransform.map(itemRect.topLeft());
QPointF topRight = itemTransform.map(itemRect.topRight());
QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft());
QLineF topLine(topLeft, topRight);
QLineF leftLine(topLeft, bottomLeft);
qreal angle = topLine.angle();
QTransform tr1;
tr1.rotate(- angle);
mResizeCursor1 = QCursor(pix.transformed(tr1, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
angle = leftLine.angle();
QTransform tr2;
tr2.rotate(- angle);
mResizeCursor2 = QCursor(pix.transformed(tr2, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
}
UBGraphicsTriangle::~UBGraphicsTriangle() UBGraphicsTriangle::~UBGraphicsTriangle()
{ {
} }
@ -65,7 +91,7 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const
void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation) void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation)
{ {
QPolygonF polygon; QPolygonF polygon;
polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h) << QPoint(x, y); polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h);
setPolygon(polygon); setPolygon(polygon);
setOrientation(orientation); setOrientation(orientation);
@ -73,56 +99,94 @@ void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsT
void UBGraphicsTriangle::setOrientation(UBGraphicsTriangleOrientation orientation) void UBGraphicsTriangle::setOrientation(UBGraphicsTriangleOrientation orientation)
{ {
if (mOrientation != orientation)
{
mOrientation = orientation; mOrientation = orientation;
QTransform t; calculatePoints(boundingRect());
switch(orientation)
QPolygonF polygon;
polygon << A1 << B1 << C1;
setPolygon(polygon);
}
UBGraphicsScene* UBGraphicsTriangle::scene() const
{
return static_cast<UBGraphicsScene*>(QGraphicsPolygonItem::scene());
}
void UBGraphicsTriangle::calculatePoints(const QRectF& r)
{
switch(mOrientation)
{ {
case BottomLeft: case BottomLeft:
t.setMatrix(1, 0, 0, 0, 1, 0, 0, 0, 1); A1.setX(r.left()); A1.setY(r.top());
B1.setX(r.left()); B1.setY(r.bottom());
C1.setX(r.right()); C1.setY(r.bottom());
break;
case TopLeft:
A1.setX(r.left()); A1.setY(r.bottom());
B1.setX(r.left()); B1.setY(r.top());
C1.setX(r.right()); C1.setY(r.top());
break;
case TopRight:
A1.setX(r.right()); A1.setY(r.bottom());
B1.setX(r.right()); B1.setY(r.top());
C1.setX(r.left()); C1.setY(r.top());
break; break;
case BottomRight: case BottomRight:
t.setMatrix(-1, 0, 0, 0, 1, 0, boundingRect().right(), 0, 1); A1.setX(r.right()); A1.setY(r.top());
B1.setX(r.right()); B1.setY(r.bottom());
C1.setX(r.left()); C1.setY(r.bottom());
break;
}
C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
qreal L = (C * d + rect().width() * d)/ rect().height();
qreal K = (C * d + rect().height() * d)/ rect().width();
switch(mOrientation)
{
case BottomLeft:
A2.setX(r.left() + d); A2.setY(r.top() + K);
B2.setX(r.left() + d); B2.setY(r.bottom() - d);
C2.setX(r.right() - L); C2.setY(r.bottom() - d);
break; break;
case TopLeft: case TopLeft:
t.setMatrix(1, 0, 0, 0, -1, 0, 0, boundingRect().bottom(), 1); A2.setX(r.left() + d); A2.setY(r.bottom() - K);
B2.setX(r.left() + d); B2.setY(r.top() + d);
C2.setX(r.right() - L); C2.setY(r.top() + d);
break; break;
case TopRight: case TopRight:
t.setMatrix(-1, 0, 0, 0, -1, 0, boundingRect().right(), boundingRect().bottom(), 1); A2.setX(r.right() - d); A2.setY(r.bottom() - K);
B2.setX(r.right() - d); B2.setY(r.top() + d);
C2.setX(r.left() + L); C2.setY(r.top() + d);
break;
case BottomRight:
A2.setX(r.right() - d); A2.setY(r.top() + K);
B2.setX(r.right() - d); B2.setY(r.bottom() - d);
C2.setX(r.left() + L); C2.setY(r.bottom() - d);
break; break;
} }
W1 = rect().height() * d / C;
H1 = rect().width() * d / C;
this->angle = -this->angle; switch(mOrientation)
rotateAroundCenter(t, rotationCenter()); {
setTransform(t); case BottomLeft:
CC.setX(r.right() - L + W1); CC.setY(r.bottom() - d - H1);
break;
case TopLeft:
CC.setX(r.right() - L + W1); CC.setY(r.top() + d + H1);
break;
case TopRight:
CC.setX(r.left() + L - W1); CC.setY(r.top() + d + H1);
break;
case BottomRight:
CC.setX(r.left() + L - W1); CC.setY(r.top() - d - H1);
break;
} }
} }
UBGraphicsScene* UBGraphicsTriangle::scene() const
{
return static_cast<UBGraphicsScene*>(QGraphicsPolygonItem::scene());
}
void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{ {
QPointF A1(rect().x(), rect().y());
QPointF B1(rect().x(), rect().y() + rect().height());
QPointF C1(rect().x() + rect().width(), rect().y() + rect().height());
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
qreal L = (C * d + rect().width() * d)/ rect().height();
qreal K = (C * d + rect().height() * d)/ rect().width();
qreal W1 = rect().height() * d / C;
qreal H1 = rect().width() * d / C;
QPointF A2(rect().x() + d, rect().y() + K);
QPointF B2(rect().x() + d, rect().y() + rect().height() - d);
QPointF C2(rect().x() + rect().width() - L, rect().y() + rect().height() - d);
QPoint CC(rect().x() + rect().width() - L + W1,
rect().y() + rect().height() - d - H1);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
@ -197,41 +261,76 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter)
const int millimetersPerCentimeter = 10; const int millimetersPerCentimeter = 10;
const int millimetersPerHalfCentimeter = 5; const int millimetersPerHalfCentimeter = 5;
qreal kx = (mOrientation == TopLeft || mOrientation == BottomLeft) ? 1 : -1;
qreal ky = (mOrientation == BottomLeft || mOrientation == BottomRight) ? 1 : -1;
painter->save(); painter->save();
painter->setFont(font()); painter->setFont(font());
QFontMetricsF fontMetrics(painter->font()); QFontMetricsF fontMetrics(painter->font());
for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++) for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++)
{ {
int graduationX = rotationCenter().x() + sPixelsPerMillimeter * millimeters; int graduationX = rotationCenter().x() + kx * sPixelsPerMillimeter * millimeters;
int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ? int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ?
centimeterGraduationHeight : centimeterGraduationHeight :
((0 == millimeters % millimetersPerHalfCentimeter) ? ((0 == millimeters % millimetersPerHalfCentimeter) ?
halfCentimeterGraduationHeight : millimeterGraduationHeight); halfCentimeterGraduationHeight : millimeterGraduationHeight);
// Check that grad. line inside triangle // Check that grad. line inside triangle
qreal lineY = rect().bottom() - rect().height()/rect().width()*(rect().width() - graduationX); qreal dx = (kx > 0) ? rect().width() - graduationX : graduationX - rect().x();
if (lineY >= rotationCenter().y() - graduationHeight) qreal lineY = rotationCenter().y() - ky * rect().height()/rect().width() * dx;
if (mOrientation == BottomLeft || mOrientation == BottomRight)
{
if (lineY >= rotationCenter().y() - ky * graduationHeight)
break;
}
else
{
if (lineY <= rotationCenter().y() - ky * graduationHeight)
break; break;
}
painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() - graduationHeight)); painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() - ky * graduationHeight));
if (0 == millimeters % millimetersPerCentimeter) if (0 == millimeters % millimetersPerCentimeter)
{ {
QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter)); QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter));
int textXRight = graduationX + fontMetrics.width(text) / 2; int textXRight = graduationX + fontMetrics.width(text) / 2;
qreal textWidth = fontMetrics.width(text); qreal textWidth = fontMetrics.width(text);
qreal textHeight = fontMetrics.tightBoundingRect(text).height() + 5; qreal textHeight = fontMetrics.tightBoundingRect(text).height() + 5;
int textY = rect().bottom() - 5 - centimeterGraduationHeight - textHeight;
lineY = rect().bottom() - rect().height()/rect().width()*(rect().width() - textXRight); int textY = (ky > 0) ? rotationCenter().y() - 5 - centimeterGraduationHeight - textHeight
: rotationCenter().y() + 5 + centimeterGraduationHeight;
if (textXRight < rect().right() bool bText = false;
&& lineY < textY) switch(mOrientation)
{ {
case BottomLeft:
dx = rect().width() - textXRight;
lineY = rotationCenter().y() - rect().height()/rect().width() * dx;
bText = lineY <= textY;
break;
case TopLeft:
dx = rect().width() - textXRight;
lineY = rotationCenter().y() + rect().height()/rect().width() * dx;
bText = lineY >= textY + textHeight;
break;
case TopRight:
dx = textXRight - textWidth - rect().left();
lineY = rotationCenter().y() + rect().height()/rect().width() * dx;
bText = lineY >= textY + textHeight;
break;
case BottomRight:
dx = textXRight - textWidth - rect().left();
lineY = rotationCenter().y() - rect().height()/rect().width() * dx;
bText = lineY <= textY;
break;
}
if (bText)
painter->drawText( painter->drawText(
QRectF(graduationX - textWidth / 2, QRectF(graduationX - textWidth / 2,
textY, textWidth, textHeight), textY, textWidth, textHeight),
Qt::AlignVCenter, text); Qt::AlignVCenter, text);
}
} }
} }
painter->restore(); painter->restore();
@ -258,82 +357,192 @@ void UBGraphicsTriangle::rotateAroundCenter(QTransform& transform, QPointF cente
QPointF UBGraphicsTriangle::rotationCenter() const QPointF UBGraphicsTriangle::rotationCenter() const
{ {
return QPointF(rect().x() + sLeftEdgeMargin , rect().bottom()); switch(mOrientation)
{
case BottomLeft:
case TopLeft:
return B1 + QPointF(sLeftEdgeMargin, 0);
case TopRight:
case BottomRight:
return B1 - QPointF(sLeftEdgeMargin, 0);
}
return QPointF(0, 0);
} }
QRectF UBGraphicsTriangle::closeButtonRect() const QRectF UBGraphicsTriangle::closeButtonRect() const
{ {
return QRectF(rect().x() + d - mCloseSvgItem->boundingRect().width() - 5, switch(mOrientation)
rect().bottom() - d - mCloseSvgItem->boundingRect().height() - 5, {
case BottomLeft:
return QRectF(B2.x() - mCloseSvgItem->boundingRect().width() - 5,
B2.y() - mCloseSvgItem->boundingRect().height() - 5,
mCloseSvgItem->boundingRect().width(),
mCloseSvgItem->boundingRect().height());
case TopLeft:
return QRectF(B2.x() - mCloseSvgItem->boundingRect().width() - 5,
B2.y() + 5,
mCloseSvgItem->boundingRect().width(),
mCloseSvgItem->boundingRect().height());
case TopRight:
return QRectF(B2.x() + 5,
B2.y() + 5,
mCloseSvgItem->boundingRect().width(),
mCloseSvgItem->boundingRect().height());
case BottomRight:
return QRectF(B2.x() + 5,
B2.y() - mCloseSvgItem->boundingRect().height() - 5,
mCloseSvgItem->boundingRect().width(), mCloseSvgItem->boundingRect().width(),
mCloseSvgItem->boundingRect().height()); mCloseSvgItem->boundingRect().height());
}
return QRectF(0,0,0,0);
} }
QPolygonF UBGraphicsTriangle::resize1Polygon() const QPolygonF UBGraphicsTriangle::resize1Polygon() const
{ {
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height()); qreal x1, y1;
switch(mOrientation)
{
case BottomLeft:
x1 = -1;
y1 = -1;
break;
case TopLeft:
x1 = -1;
y1 = 1;
break;
case TopRight:
x1 = 1;
y1 = 1;
break;
case BottomRight:
x1 = 1;
y1 = -1;
break;
}
QPointF P1(C1.x() + x1 * sArrowLength, C1.y());
QPointF P2(C1.x() + x1 * sArrowLength * rect().width()/C, C1.y() + y1 * sArrowLength * rect().height() / C);
QPolygonF p; QPolygonF p;
p << C1 << P1 << P2;
QPointF P1(rect().right() - sArrowLength, rect().bottom());
QPointF P2(rect().right() - sArrowLength * rect().width() / C,
rect().bottom() - sArrowLength * rect().height() / C );
p << QPointF(rect().right(), rect().bottom()) << P1 << P2;
return p; return p;
} }
QPolygonF UBGraphicsTriangle::resize2Polygon() const QPolygonF UBGraphicsTriangle::resize2Polygon() const
{ {
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height()); qreal x1, y1;
switch(mOrientation)
{
case BottomLeft:
x1 = 1;
y1 = 1;
break;
case TopLeft:
x1 = 1;
y1 = -1;
break;
case TopRight:
x1 = -1;
y1 = -1;
break;
case BottomRight:
x1 = -1;
y1 = 1;
break;
}
QPointF P1(A1.x(), A1.y() + y1 * sArrowLength);
QPointF P2(A1.x() + x1 * sArrowLength * rect().width()/C,
A1.y() + y1 * sArrowLength * rect().height() / C);
QPolygonF p; QPolygonF p;
p << A1 << P1 << P2;
QPointF P1(rect().left(), rect().top() + sArrowLength);
QPointF P2(rect().left() + sArrowLength * rect().width() / C,
rect().top() + sArrowLength * rect().height() / C );
p << QPointF(rect().left(), rect().top()) << P1 << P2;
return p; return p;
} }
QRectF UBGraphicsTriangle::hFlipRect() const QRectF UBGraphicsTriangle::hFlipRect() const
{ {
return QRectF(rect().x() + d - mHFlipSvgItem->boundingRect().width() - 5, qreal dy = mVFlipSvgItem->boundingRect().height() + mCloseSvgItem->boundingRect().height() + 10;
rect().bottom() - d - mCloseSvgItem->boundingRect().height() - mVFlipSvgItem->boundingRect().height() - switch(mOrientation)
mVFlipSvgItem->boundingRect().height() - 15, {
case BottomLeft:
return QRectF(B2.x() - mHFlipSvgItem->boundingRect().width() - 5,
B2.y() - mHFlipSvgItem->boundingRect().height() - 5 - dy,
mHFlipSvgItem->boundingRect().width(),
mHFlipSvgItem->boundingRect().height());
case TopLeft:
return QRectF(B2.x() - mHFlipSvgItem->boundingRect().width() - 5,
B2.y() + 5 + dy,
mHFlipSvgItem->boundingRect().width(),
mHFlipSvgItem->boundingRect().height());
case TopRight:
return QRectF(B2.x() + 5,
B2.y() + 5 + dy,
mHFlipSvgItem->boundingRect().width(),
mHFlipSvgItem->boundingRect().height());
case BottomRight:
return QRectF(B2.x() + 5,
B2.y() - mHFlipSvgItem->boundingRect().height() - 5 - dy,
mHFlipSvgItem->boundingRect().width(), mHFlipSvgItem->boundingRect().width(),
mHFlipSvgItem->boundingRect().height()); mHFlipSvgItem->boundingRect().height());
}
return QRectF(0,0,0,0);
} }
QRectF UBGraphicsTriangle::vFlipRect() const QRectF UBGraphicsTriangle::vFlipRect() const
{ {
return QRectF(rect().x() + d - mVFlipSvgItem->boundingRect().width() - 5, qreal dy = mCloseSvgItem->boundingRect().height() + 5;
rect().bottom() - d - mCloseSvgItem->boundingRect().height() - mVFlipSvgItem->boundingRect().height() - 10, switch(mOrientation)
{
case BottomLeft:
return QRectF(B2.x() - mVFlipSvgItem->boundingRect().width() - 5,
B2.y() - mVFlipSvgItem->boundingRect().height() - 5 - dy,
mVFlipSvgItem->boundingRect().width(),
mVFlipSvgItem->boundingRect().height());
case TopLeft:
return QRectF(B2.x() - mVFlipSvgItem->boundingRect().width() - 5,
B2.y() + 5 + dy,
mVFlipSvgItem->boundingRect().width(),
mVFlipSvgItem->boundingRect().height());
case TopRight:
return QRectF(B2.x() + 5,
B2.y() + 5 + dy,
mVFlipSvgItem->boundingRect().width(), mVFlipSvgItem->boundingRect().width(),
mVFlipSvgItem->boundingRect().height()); mVFlipSvgItem->boundingRect().height());
case BottomRight:
return QRectF(B2.x() + 5,
B2.y() - mVFlipSvgItem->boundingRect().height() - 5 - dy,
mVFlipSvgItem->boundingRect().width(),
mVFlipSvgItem->boundingRect().height());
}
return QRectF(0,0,0,0);
} }
QRectF UBGraphicsTriangle::rotateRect() const QRectF UBGraphicsTriangle::rotateRect() const
{ {
QPointF A1(rect().x(), rect().y()); QPointF p(C2);
QPointF B1(rect().x(), rect().y() + rect().height()); switch(mOrientation)
QPointF C1(rect().x() + rect().width(), rect().y() + rect().height()); {
case BottomLeft:
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height()); p += QPointF(20, 5);
qreal L = (C * d + rect().width() * d)/ rect().height(); break;
case TopLeft:
QPointF C2(rect().x() + rect().width() - L, rect().y() + rect().height() - d); p += QPointF(20, -5 - mRotateSvgItem->boundingRect().height());
break;
return QRectF(C2 + QPointF(20, 5), QSizeF(mRotateSvgItem->boundingRect().size())); case TopRight:
p += QPointF(-20 - mRotateSvgItem->boundingRect().width(), -5 - mRotateSvgItem->boundingRect().height());
break;
case BottomRight:
p += QPointF(-20 - mRotateSvgItem->boundingRect().width(), 5);
break;
}
return QRectF(p, QSizeF(mRotateSvgItem->boundingRect().size()));
}
QCursor UBGraphicsTriangle::resizeCursor1() const
{
return mResizeCursor1;
} }
QCursor UBGraphicsTriangle::moveResizeCursor() const QCursor UBGraphicsTriangle::resizeCursor2() const
{ {
return Qt::OpenHandCursor; return mResizeCursor2;
} }
QCursor UBGraphicsTriangle::flipCursor() const QCursor UBGraphicsTriangle::flipCursor() const
@ -382,8 +591,16 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (mResizing1) if (mResizing1)
{ {
QPointF delta = event->pos() - event->lastPos(); QPointF delta = event->pos() - event->lastPos();
if (mOrientation == TopLeft || mOrientation == BottomLeft)
{
if (rect().width() + delta.x() < sMinWidth) if (rect().width() + delta.x() < sMinWidth)
delta.setX(sMinWidth - rect().width()); delta.setX(sMinWidth - rect().width());
}
else
{
if (rect().width() - delta.x() < sMinWidth)
delta.setX(sMinWidth - rect().width());
}
if (mOrientation == TopLeft || mOrientation == BottomLeft) if (mOrientation == TopLeft || mOrientation == BottomLeft)
{ {
setRect(QRectF( setRect(QRectF(
@ -395,9 +612,9 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
else else
{ {
setRect(QRectF( setRect(QRectF(
rect().left() - delta.x(), rect().left() + delta.x(),
rect().top(), rect().top(),
rect().width() + delta.x(), rect().width() - delta.x(),
rect().height()), rect().height()),
mOrientation mOrientation
); );
@ -406,18 +623,30 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (mResizing2) if (mResizing2)
{ {
QPointF delta = event->pos() - event->lastPos(); QPointF delta = event->pos() - event->lastPos();
if (mOrientation == BottomRight || mOrientation == BottomLeft)
{
if (rect().height() - delta.y() < sMinHeight) if (rect().height() - delta.y() < sMinHeight)
delta.setY(sMinHeight - rect().height()); delta.setY(sMinHeight - rect().height());
qDebug() << event->pos() << event->lastPos() << delta; }
QRectF r( else
{
if (rect().height() + delta.y() < sMinHeight)
delta.setY(sMinHeight - rect().height());
}
if (mOrientation == BottomRight || mOrientation == BottomLeft)
setRect(QRectF(
rect().left(), rect().left(),
rect().top() + delta.y(), rect().top() + delta.y(),
rect().width(), rect().width(),
rect().height() - delta.y()); rect().height() - delta.y()),
qDebug() << r; mOrientation);
setRect(r, mOrientation); else
setRect(QRectF(
rect().left(),
rect().top(),
rect().width(),
rect().height() + delta.y()),
mOrientation);
} }
if (mRotating) if (mRotating)
{ {
@ -434,6 +663,8 @@ void UBGraphicsTriangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (mResizing1 || mResizing2 || mRotating) if (mResizing1 || mResizing2 || mRotating)
{ {
if (mRotating)
updateResizeCursor();
mResizing1 = false; mResizing1 = false;
mResizing2 = false; mResizing2 = false;
mRotating = false; mRotating = false;
@ -505,9 +736,10 @@ void UBGraphicsTriangle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
mVFlipSvgItem->setVisible(true); mVFlipSvgItem->setVisible(true);
mRotateSvgItem->setVisible(true); mRotateSvgItem->setVisible(true);
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill) || if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill)) setCursor(resizeCursor1());
setCursor(moveResizeCursor()); else if(resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
setCursor(resizeCursor2());
else if (closeButtonRect().contains(event->pos())) else if (closeButtonRect().contains(event->pos()))
setCursor(closeCursor()); setCursor(closeCursor());
else if (hFlipRect().contains(event->pos()) else if (hFlipRect().contains(event->pos())
@ -546,9 +778,10 @@ void UBGraphicsTriangle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
mHFlipSvgItem->setVisible(mShowButtons); mHFlipSvgItem->setVisible(mShowButtons);
mRotateSvgItem->setVisible(mShowButtons); mRotateSvgItem->setVisible(mShowButtons);
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill) || if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill)) setCursor(resizeCursor1());
setCursor(moveResizeCursor()); else if (resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
setCursor(resizeCursor2());
else if (closeButtonRect().contains(event->pos())) else if (closeButtonRect().contains(event->pos()))
setCursor(closeCursor()); setCursor(closeCursor());
else if (hFlipRect().contains(event->pos()) else if (hFlipRect().contains(event->pos())

@ -67,6 +67,8 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
protected: protected:
void updateResizeCursor();
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
virtual void rotateAroundCenter(qreal angle); virtual void rotateAroundCenter(qreal angle);
@ -80,7 +82,9 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
QRectF vFlipRect() const; QRectF vFlipRect() const;
QRectF rotateRect() const; QRectF rotateRect() const;
QCursor moveResizeCursor() const; QCursor resizeCursor1() const;
QCursor resizeCursor2() const;
QCursor flipCursor() const; QCursor flipCursor() const;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
@ -92,6 +96,9 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
private: private:
QCursor mResizeCursor1;
QCursor mResizeCursor2;
QTransform calculateRotationTransform(); QTransform calculateRotationTransform();
qreal angle; qreal angle;
void rotateAroundCenter(QTransform& transform, QPointF center); void rotateAroundCenter(QTransform& transform, QPointF center);
@ -112,9 +119,15 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
UBGraphicsTriangleOrientation mOrientation; UBGraphicsTriangleOrientation mOrientation;
QPointF A1, B1, C1, A2, B2, C2; // coordinates of points in ext and int triangles
qreal C;
qreal W1, H1; // Neccessary for filling
QPointF CC; // Hyp. fillining gradient - top point
void calculatePoints(const QRectF& rect);
static const int d = 70; // width of triangle border static const int d = 70; // width of triangle border
static const int sArrowLength = 30; static const int sArrowLength = 30;
static const int sMinWidth = 200; static const int sMinWidth = 380;
static const int sMinHeight = 200; static const int sMinHeight = 200;
}; };

Loading…
Cancel
Save