|
|
@ -13,6 +13,7 @@ |
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "board/UBDrawingController.h" |
|
|
|
#include "board/UBDrawingController.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "core/memcheck.h" |
|
|
|
#include "core/memcheck.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -30,6 +31,8 @@ UBGraphicsProtractor::UBGraphicsProtractor() |
|
|
|
, mResizeSvgItem(0) |
|
|
|
, mResizeSvgItem(0) |
|
|
|
, mMarkerSvgItem(0) |
|
|
|
, mMarkerSvgItem(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
sFillTransparency = 127; |
|
|
|
|
|
|
|
sDrawTransparency = 192; |
|
|
|
|
|
|
|
|
|
|
|
create(*this); |
|
|
|
create(*this); |
|
|
|
|
|
|
|
|
|
|
@ -125,7 +128,7 @@ QPainterPath UBGraphicsProtractor::shape() const |
|
|
|
qreal centerY = center.y(); |
|
|
|
qreal centerY = center.y(); |
|
|
|
|
|
|
|
|
|
|
|
buttonPath.addRect(resizeButtonRect().adjusted(centerX, centerY, centerX, centerY)); |
|
|
|
buttonPath.addRect(resizeButtonRect().adjusted(centerX, centerY, centerX, centerY)); |
|
|
|
if(!resizeButtonRect().contains(markerRect)) |
|
|
|
if (!resizeButtonRect().contains(markerRect)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
buttonPath.addRect(markerRect.adjusted(centerX - markerRect.left() * 2 - markerRect.width(), centerY |
|
|
|
buttonPath.addRect(markerRect.adjusted(centerX - markerRect.left() * 2 - markerRect.width(), centerY |
|
|
|
, centerX - markerRect.left() * 2 - markerRect.width(), centerY)); |
|
|
|
, centerX - markerRect.left() * 2 - markerRect.width(), centerY)); |
|
|
@ -166,7 +169,7 @@ void UBGraphicsProtractor::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
qreal angle = startLine.angleTo(currentLine); |
|
|
|
qreal angle = startLine.angleTo(currentLine); |
|
|
|
qreal scaleFactor = currentLine.length()/startLine.length(); |
|
|
|
qreal scaleFactor = currentLine.length()/startLine.length(); |
|
|
|
|
|
|
|
|
|
|
|
switch(mCurrentTool) |
|
|
|
switch (mCurrentTool) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case Rotate : |
|
|
|
case Rotate : |
|
|
|
prepareGeometryChange(); |
|
|
|
prepareGeometryChange(); |
|
|
@ -186,9 +189,9 @@ void UBGraphicsProtractor::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
case MoveMarker : |
|
|
|
case MoveMarker : |
|
|
|
|
|
|
|
|
|
|
|
mCurrentAngle += angle; |
|
|
|
mCurrentAngle += angle; |
|
|
|
if((int)mCurrentAngle % 360 > 270) |
|
|
|
if ((int)mCurrentAngle % 360 > 270) |
|
|
|
mCurrentAngle = 0; |
|
|
|
mCurrentAngle = 0; |
|
|
|
else if((int)mCurrentAngle % 360 >= 180) |
|
|
|
else if ((int)mCurrentAngle % 360 >= 180) |
|
|
|
mCurrentAngle = 180; |
|
|
|
mCurrentAngle = 180; |
|
|
|
|
|
|
|
|
|
|
|
mPreviousMousePos = currentPoint; |
|
|
|
mPreviousMousePos = currentPoint; |
|
|
@ -203,7 +206,7 @@ void UBGraphicsProtractor::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(mCurrentTool != Move) |
|
|
|
if (mCurrentTool != Move) |
|
|
|
event->accept(); |
|
|
|
event->accept(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -211,7 +214,7 @@ void UBGraphicsProtractor::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsProtractor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
void UBGraphicsProtractor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch(mCurrentTool) |
|
|
|
switch (mCurrentTool) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case Reset : |
|
|
|
case Reset : |
|
|
|
setStartAngle(0); |
|
|
|
setStartAngle(0); |
|
|
@ -286,7 +289,7 @@ void UBGraphicsProtractor::hoverMoveEvent(QGraphicsSceneHoverEvent *event) |
|
|
|
update(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(currentTool == Move) |
|
|
|
if (currentTool == Move) |
|
|
|
setCursor(Qt::SizeAllCursor); |
|
|
|
setCursor(Qt::SizeAllCursor); |
|
|
|
else |
|
|
|
else |
|
|
|
setCursor(Qt::ArrowCursor); |
|
|
|
setCursor(Qt::ArrowCursor); |
|
|
@ -305,7 +308,7 @@ QRectF UBGraphicsProtractor::resetButtonRect () const |
|
|
|
{ |
|
|
|
{ |
|
|
|
qreal antiSc = antiScale(); |
|
|
|
qreal antiSc = antiScale(); |
|
|
|
|
|
|
|
|
|
|
|
if(buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15) |
|
|
|
if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15) |
|
|
|
return QRectF(-buttonSizeReference().width() * 7, -buttonSizeReference().height() * antiSc / 2, |
|
|
|
return QRectF(-buttonSizeReference().width() * 7, -buttonSizeReference().height() * antiSc / 2, |
|
|
|
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); |
|
|
|
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); |
|
|
|
else |
|
|
|
else |
|
|
@ -334,7 +337,7 @@ QRectF UBGraphicsProtractor::resizeButtonRect () const |
|
|
|
{ |
|
|
|
{ |
|
|
|
qreal antiSc = antiScale(); |
|
|
|
qreal antiSc = antiScale(); |
|
|
|
|
|
|
|
|
|
|
|
if(buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15) |
|
|
|
if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15) |
|
|
|
return QRectF(buttonSizeReference().width() * 8, -buttonSizeReference().height() * antiSc / 2, |
|
|
|
return QRectF(buttonSizeReference().width() * 8, -buttonSizeReference().height() * antiSc / 2, |
|
|
|
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); |
|
|
|
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); |
|
|
|
else |
|
|
|
else |
|
|
@ -370,12 +373,12 @@ void UBGraphicsProtractor::paintGraduations(QPainter *painter) |
|
|
|
QPointF center = rect().center(); |
|
|
|
QPointF center = rect().center(); |
|
|
|
painter->drawArc(QRectF(center.x() - rad/2, center.y() - rad/2, rad, rad), mStartAngle*16, mSpan*16); |
|
|
|
painter->drawArc(QRectF(center.x() - rad/2, center.y() - rad/2, rad, rad), mStartAngle*16, mSpan*16); |
|
|
|
|
|
|
|
|
|
|
|
for(int angle = 1; angle < mSpan; angle++) |
|
|
|
for (int angle = 1; angle < mSpan; angle++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int graduationLength = (0 == angle % 10) ? tenDegreeGraduationLength : ((0 == angle % 5) ? fiveDegreeGraduationLength : oneDegreeGraduationLength); |
|
|
|
int graduationLength = (0 == angle % 10) ? tenDegreeGraduationLength : ((0 == angle % 5) ? fiveDegreeGraduationLength : oneDegreeGraduationLength); |
|
|
|
qreal co = cos(((qreal)angle + mStartAngle) * PI/180); |
|
|
|
qreal co = cos(((qreal)angle + mStartAngle) * PI/180); |
|
|
|
qreal si = sin(((qreal)angle + mStartAngle) * PI/180); |
|
|
|
qreal si = sin(((qreal)angle + mStartAngle) * PI/180); |
|
|
|
if(0 == angle % 90) |
|
|
|
if (0 == angle % 90) |
|
|
|
painter->drawLine(QLineF(QPointF(center.x(), center.y()), QPointF(center.x() + co*tenDegreeGraduationLength, center.y() - si*tenDegreeGraduationLength))); |
|
|
|
painter->drawLine(QLineF(QPointF(center.x(), center.y()), QPointF(center.x() + co*tenDegreeGraduationLength, center.y() - si*tenDegreeGraduationLength))); |
|
|
|
|
|
|
|
|
|
|
|
//external arc
|
|
|
|
//external arc
|
|
|
@ -415,7 +418,7 @@ void UBGraphicsProtractor::paintButtons(QPainter *painter) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_UNUSED(painter); |
|
|
|
Q_UNUSED(painter); |
|
|
|
|
|
|
|
|
|
|
|
if(mShowButtons) |
|
|
|
if (mShowButtons) |
|
|
|
{ |
|
|
|
{ |
|
|
|
qreal antiSc = antiScale(); |
|
|
|
qreal antiSc = antiScale(); |
|
|
|
|
|
|
|
|
|
|
@ -495,7 +498,7 @@ void UBGraphicsProtractor::paintAngleMarker(QPainter *painter) |
|
|
|
|
|
|
|
|
|
|
|
qreal angle = mCurrentAngle - (int)(mCurrentAngle/360)*360; |
|
|
|
qreal angle = mCurrentAngle - (int)(mCurrentAngle/360)*360; |
|
|
|
|
|
|
|
|
|
|
|
if(angle != 0) |
|
|
|
if (angle != 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QString ang = QString("%1°").arg(angle,0, 'f', 1); |
|
|
|
QString ang = QString("%1°").arg(angle,0, 'f', 1); |
|
|
|
QFont font2 = painter->font(); |
|
|
|
QFont font2 = painter->font(); |
|
|
@ -528,17 +531,17 @@ UBGraphicsProtractor::Tool UBGraphicsProtractor::toolFromPos(QPointF pos) |
|
|
|
t.rotate(mCurrentAngle); |
|
|
|
t.rotate(mCurrentAngle); |
|
|
|
QPointF p2 = t.map(pos); |
|
|
|
QPointF p2 = t.map(pos); |
|
|
|
|
|
|
|
|
|
|
|
if(resizeButtonRect().contains(p1)) |
|
|
|
if (resizeButtonRect().contains(p1)) |
|
|
|
return Resize; |
|
|
|
return Resize; |
|
|
|
else if(closeButtonRect().contains(p1)) |
|
|
|
else if (closeButtonRect().contains(p1)) |
|
|
|
return Close; |
|
|
|
return Close; |
|
|
|
else if(resetButtonRect().contains(p1)) |
|
|
|
else if (resetButtonRect().contains(p1)) |
|
|
|
return Reset; |
|
|
|
return Reset; |
|
|
|
else if(rotateButtonRect().contains(p1)) |
|
|
|
else if (rotateButtonRect().contains(p1)) |
|
|
|
return Rotate; |
|
|
|
return Rotate; |
|
|
|
else if(markerButtonRect().contains(p2)) |
|
|
|
else if (markerButtonRect().contains(p2)) |
|
|
|
return MoveMarker; |
|
|
|
return MoveMarker; |
|
|
|
else if(line.length() <= radius()) |
|
|
|
else if (line.length() <= radius()) |
|
|
|
return Move; |
|
|
|
return Move; |
|
|
|
else |
|
|
|
else |
|
|
|
return None; |
|
|
|
return None; |
|
|
@ -584,7 +587,9 @@ UBItem* UBGraphicsProtractor::deepCopy() const |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsProtractor::rotateAroundTopLeftOrigin(qreal angle) |
|
|
|
void UBGraphicsProtractor::rotateAroundTopLeftOrigin(qreal angle) |
|
|
|
{} |
|
|
|
{ |
|
|
|
|
|
|
|
Q_UNUSED(angle); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QPointF UBGraphicsProtractor::topLeftOrigin() const |
|
|
|
QPointF UBGraphicsProtractor::topLeftOrigin() const |
|
|
|
{ |
|
|
|
{ |
|
|
|