fixed some errors on OS other than win

preferencesAboutTextFull
Claudio Valerio 14 years ago
parent 92b664b306
commit b485765eec
  1. 21
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 125
      src/tools/UBAbstractDrawRuler.h
  3. 239
      src/tools/UBGraphicsProtractor.cpp
  4. 10
      src/tools/UBGraphicsProtractor.h

@ -2576,31 +2576,18 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg()
graphicsItemFromSvg(triangle); graphicsItemFromSvg(triangle);
//QStringRef angle = mXmlReader.attributes().value(mNamespaceUri, "angle");
//if (!angle.isNull())
//{
// protractor->setAngle(angle.toString().toFloat());
//}
//QStringRef markerAngle = mXmlReader.attributes().value(mNamespaceUri, "marker-angle");
//if (!markerAngle.isNull())
//{
// protractor->setMarkerAngle(markerAngle.toString().toFloat());
//}
QStringRef svgX = mXmlReader.attributes().value("x"); QStringRef svgX = mXmlReader.attributes().value("x");
QStringRef svgY = mXmlReader.attributes().value("y"); QStringRef svgY = mXmlReader.attributes().value("y");
QStringRef svgWidth = mXmlReader.attributes().value("width"); QStringRef svgWidth = mXmlReader.attributes().value("width");
QStringRef svgHeight = mXmlReader.attributes().value("height"); QStringRef svgHeight = mXmlReader.attributes().value("height");
UBGraphicsTriangle::UBGraphicsTriangleOrientation orientation =
UBGraphicsTriangle::orientationFromStr((mXmlReader.attributes().value("orientation"))); QStringRef orientationStringRef = mXmlReader.attributes().value("orientation");
UBGraphicsTriangle::UBGraphicsTriangleOrientation orientation = UBGraphicsTriangle::orientationFromStr(orientationStringRef);
if (!svgX.isNull() && !svgY.isNull() && !svgWidth.isNull() && !svgHeight.isNull()) if (!svgX.isNull() && !svgY.isNull() && !svgWidth.isNull() && !svgHeight.isNull())
{ {
triangle->setRect(svgX.toString().toFloat(), svgY.toString().toFloat() triangle->setRect(svgX.toString().toFloat(), svgY.toString().toFloat(), svgWidth.toString().toFloat(), svgHeight.toString().toFloat(), orientation);
, svgWidth.toString().toFloat(), svgHeight.toString().toFloat(),
orientation);
} }
triangle->setVisible(true); triangle->setVisible(true);

@ -7,68 +7,69 @@ class QGraphicsSvgItem;
class UBAbstractDrawRuler : public QObject class UBAbstractDrawRuler : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
UBAbstractDrawRuler(); UBAbstractDrawRuler();
~UBAbstractDrawRuler(); ~UBAbstractDrawRuler();
void create(QGraphicsItem& item); void create(QGraphicsItem& item);
virtual void StartLine(const QPointF& position, qreal width); virtual void StartLine(const QPointF& position, qreal width);
virtual void DrawLine(const QPointF& position, qreal width); virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine(); virtual void EndLine();
protected:
protected:
void paint();
void paint();
virtual UBGraphicsScene* scene() const = 0;
virtual UBGraphicsScene* scene() const = 0;
virtual void rotateAroundTopLeftOrigin(qreal angle) = 0;
virtual void rotateAroundTopLeftOrigin(qreal angle) = 0;
virtual QPointF topLeftOrigin() const = 0;
virtual QRectF resizeButtonRect() const = 0; virtual QPointF topLeftOrigin() const = 0;
virtual QRectF closeButtonRect() const = 0; virtual QRectF resizeButtonRect() const = 0;
virtual QRectF rotateButtonRect() const = 0; virtual QRectF closeButtonRect() const = 0;
virtual QRectF rotateButtonRect() const = 0;
void updateResizeCursor(QGraphicsItem &item);
void updateResizeCursor(QGraphicsItem &item);
bool mResizing;
bool mRotating; bool mResizing;
bool mShowButtons; bool mRotating;
QGraphicsSvgItem* mCloseSvgItem; bool mShowButtons;
QGraphicsSvgItem* mRotateSvgItem; QGraphicsSvgItem* mCloseSvgItem;
QCursor mResizeCursor; QGraphicsSvgItem* mRotateSvgItem;
qreal mAntiScaleRatio; QCursor mResizeCursor;
qreal mAntiScaleRatio;
QPointF startDrawPosition;
QPointF startDrawPosition;
QCursor moveCursor() const;
QCursor resizeCursor() const; QCursor moveCursor() const;
QCursor rotateCursor() const; QCursor resizeCursor() const;
QCursor closeCursor() const; QCursor rotateCursor() const;
QCursor drawRulerLineCursor() const; QCursor closeCursor() const;
QCursor drawRulerLineCursor() const;
QColor drawColor() const;
QColor middleFillColor() const; QColor drawColor() const;
QColor edgeFillColor() const; QColor middleFillColor() const;
QFont font() const; QColor edgeFillColor() const;
QFont font() const;
static const QColor sLightBackgroundEdgeFillColor;
static const QColor sLightBackgroundMiddleFillColor; static const QColor sLightBackgroundEdgeFillColor;
static const QColor sLightBackgroundDrawColor; static const QColor sLightBackgroundMiddleFillColor;
static const QColor sDarkBackgroundEdgeFillColor; static const QColor sLightBackgroundDrawColor;
static const QColor sDarkBackgroundMiddleFillColor; static const QColor sDarkBackgroundEdgeFillColor;
static const QColor sDarkBackgroundDrawColor; static const QColor sDarkBackgroundMiddleFillColor;
static const QColor sDarkBackgroundDrawColor;
static const int sLeftEdgeMargin = 10;
static const int sMinLength = 150; static const int sLeftEdgeMargin = 10;
static const int sDegreeToQtAngleUnit = 16; static const int sMinLength = 150;
static const int sRotationRadius = 15; static const int sDegreeToQtAngleUnit = 16;
static const int sPixelsPerMillimeter = 5; static const int sRotationRadius = 15;
static const int sFillTransparency = 127; static const int sPixelsPerMillimeter = 5;
static const int sDrawTransparency = 192; static const int sFillTransparency = 127;
static const int sRoundingRadius = sLeftEdgeMargin / 2; static const int sDrawTransparency = 192;
static const int sRoundingRadius = sLeftEdgeMargin / 2;
}; };

@ -13,30 +13,33 @@
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "board/UBDrawingController.h" #include "board/UBDrawingController.h"
#include "core/memcheck.h" #include "core/memcheck.h"
const QRectF UBGraphicsProtractor::sDefaultRect = QRectF(-175, -175, 350, 350); const QRectF UBGraphicsProtractor::sDefaultRect = QRectF(-175, -175, 350, 350);
UBGraphicsProtractor::UBGraphicsProtractor() UBGraphicsProtractor::UBGraphicsProtractor()
: QGraphicsEllipseItem(sDefaultRect) : QGraphicsEllipseItem(sDefaultRect)
, mCurrentTool(None) , mCurrentTool(None)
, mShowButtons(false) , mShowButtons(false)
, mCurrentAngle(0) , mCurrentAngle(0)
, mSpan(180) , mSpan(180)
, mStartAngle(0) , mStartAngle(0)
, mScaleFactor(1) , mScaleFactor(1)
, mResetSvgItem(0) , mResetSvgItem(0)
, mResizeSvgItem(0) , mResizeSvgItem(0)
, mMarkerSvgItem(0) , mMarkerSvgItem(0)
{ {
sFillTransparency = 127;
sDrawTransparency = 192;
create(*this); create(*this);
setCacheMode(QGraphicsItem::DeviceCoordinateCache); setCacheMode(QGraphicsItem::DeviceCoordinateCache);
setStartAngle(0); setStartAngle(0);
setSpanAngle(180 * 16); setSpanAngle(180 * 16);
mResetSvgItem = new QGraphicsSvgItem(":/images/resetTool.svg", this); mResetSvgItem = new QGraphicsSvgItem(":/images/resetTool.svg", this);
mResetSvgItem->setVisible(false); mResetSvgItem->setVisible(false);
@ -68,7 +71,7 @@ void UBGraphicsProtractor::paint(QPainter *painter, const QStyleOptionGraphicsIt
painter->setPen(drawColor()); painter->setPen(drawColor());
painter->setBrush(fillBrush()); painter->setBrush(fillBrush());
painter->drawPie(QRectF(rect().center().x() - radius(), rect().center().y() - radius(), painter->drawPie(QRectF(rect().center().x() - radius(), rect().center().y() - radius(),
2 * radius(), 2 * radius()), mStartAngle * 16, mSpan * 16); 2 * radius(), 2 * radius()), mStartAngle * 16, mSpan * 16);
paintGraduations(painter); paintGraduations(painter);
paintButtons(painter); paintButtons(painter);
paintAngleMarker(painter); paintAngleMarker(painter);
@ -125,10 +128,10 @@ 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));
buttonPath.addRect(markerRect.adjusted(centerX, centerY, centerX, centerY)); buttonPath.addRect(markerRect.adjusted(centerX, centerY, centerX, centerY));
} }
buttonPath.addRect(closeButtonRect().adjusted(centerX, centerY, centerX, centerY)); buttonPath.addRect(closeButtonRect().adjusted(centerX, centerY, centerX, centerY));
@ -166,44 +169,44 @@ 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();
mStartAngle = mStartAngle + angle; mStartAngle = mStartAngle + angle;
setStartAngle(mStartAngle * 16); setStartAngle(mStartAngle * 16);
mPreviousMousePos = currentPoint; mPreviousMousePos = currentPoint;
break; break;
case Resize : case Resize :
prepareGeometryChange(); prepareGeometryChange();
translate(rect().center().x(), rect().center().y()); translate(rect().center().x(), rect().center().y());
scale(scaleFactor, scaleFactor); scale(scaleFactor, scaleFactor);
translate(-rect().center().x(), -rect().center().y()); translate(-rect().center().x(), -rect().center().y());
mScaleFactor *= scaleFactor; mScaleFactor *= scaleFactor;
break; break;
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;
update(); update();
break; break;
case Move : case Move :
QGraphicsEllipseItem::mouseMoveEvent(event); QGraphicsEllipseItem::mouseMoveEvent(event);
break; break;
default : default :
break; break;
} }
if(mCurrentTool != Move) if (mCurrentTool != Move)
event->accept(); event->accept();
} }
@ -211,25 +214,25 @@ 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);
mStartAngle = 0; mStartAngle = 0;
break; break;
case Close : case Close :
hide(); hide();
emit hidden(); emit hidden();
break; break;
case MoveMarker : case MoveMarker :
update(); update();
break; break;
default : default :
QGraphicsEllipseItem::mouseReleaseEvent(event); QGraphicsEllipseItem::mouseReleaseEvent(event);
break; break;
} }
if (mCurrentTool != Move) if (mCurrentTool != Move)
@ -244,8 +247,8 @@ void UBGraphicsProtractor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void UBGraphicsProtractor::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsProtractor::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector) if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
return; return;
if (!mShowButtons) if (!mShowButtons)
{ {
@ -275,8 +278,8 @@ void UBGraphicsProtractor::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void UBGraphicsProtractor::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsProtractor::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{ {
if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector) if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
return; return;
Tool currentTool = toolFromPos(event->pos()); Tool currentTool = toolFromPos(event->pos());
@ -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,12 +308,12 @@ 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
return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
} }
@ -320,13 +323,13 @@ QRectF UBGraphicsProtractor::closeButtonRect () const
if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 2) if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 2)
return QRectF(-buttonSizeReference().width() * 9, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * 9, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
else if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15) else if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15)
return QRectF(-buttonSizeReference().width() * 7 -buttonSizeReference().width() * antiSc, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * 7 -buttonSizeReference().width() * antiSc, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
else else
return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
} }
@ -334,14 +337,14 @@ 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
{ {
mResizeSvgItem->setZValue(zValue()+10); mResizeSvgItem->setZValue(zValue()+10);
return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
} }
} }
@ -356,7 +359,7 @@ void UBGraphicsProtractor::paintGraduations(QPainter *painter)
QFont font1 = painter->font(); QFont font1 = painter->font();
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
font1.setPointSizeF(font1.pointSizeF() - 3); font1.setPointSizeF(font1.pointSizeF() - 3);
#endif #endif
QFontMetricsF fm1(font1); QFontMetricsF fm1(font1);
@ -370,21 +373,21 @@ 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
painter->drawLine(QLineF(QPointF(center.x()+ rad*co, center.y() - rad*si), painter->drawLine(QLineF(QPointF(center.x()+ rad*co, center.y() - rad*si),
QPointF(center.x()+ (rad - graduationLength)*co, center.y() - (rad - graduationLength)*si))); QPointF(center.x()+ (rad - graduationLength)*co, center.y() - (rad - graduationLength)*si)));
//internal arc //internal arc
painter->drawLine(QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si), painter->drawLine(QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si),
QPointF(center.x()+ (rad/2 + graduationLength)*co, QPointF(center.x()+ (rad/2 + graduationLength)*co,
center.y() - (rad/2 + graduationLength)*si))); center.y() - (rad/2 + graduationLength)*si)));
if (0 == angle % 10) if (0 == angle % 10)
{ {
@ -394,14 +397,14 @@ void UBGraphicsProtractor::paintGraduations(QPainter *painter)
QString grad2 = QString("%1").arg((int)(mSpan - angle)); QString grad2 = QString("%1").arg((int)(mSpan - angle));
painter->drawText(QRectF(center.x() + (rad - graduationLength*1.5)*co - fm1.width(grad)/2, painter->drawText(QRectF(center.x() + (rad - graduationLength*1.5)*co - fm1.width(grad)/2,
center.y() - (rad - graduationLength*1.5)*si - fm1.height()/2, center.y() - (rad - graduationLength*1.5)*si - fm1.height()/2,
fm1.width(grad), fm1.height()), Qt::AlignTop, grad); fm1.width(grad), fm1.height()), Qt::AlignTop, grad);
//internal arc //internal arc
painter->setFont(font2); painter->setFont(font2);
painter->drawText(QRectF(center.x() + (rad/2 + graduationLength*1.5)*co - fm2.width(grad2)/2, painter->drawText(QRectF(center.x() + (rad/2 + graduationLength*1.5)*co - fm2.width(grad2)/2,
center.y() - (rad/2 + graduationLength*1.5)*si - fm2.height()/2, center.y() - (rad/2 + graduationLength*1.5)*si - fm2.height()/2,
fm2.width(grad2), fm2.height()), Qt::AlignTop, grad2); fm2.width(grad2), fm2.height()), Qt::AlignTop, grad2);
painter->setFont(font1); painter->setFont(font1);
} }
@ -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();
@ -480,14 +483,14 @@ void UBGraphicsProtractor::paintAngleMarker(QPainter *painter)
painter->drawLine(QLineF(rect().center(), QPointF(rect().center().x()+ (rad+ 20)*co, rect().center().y() - (rad + 20)*si))); painter->drawLine(QLineF(rect().center(), QPointF(rect().center().x()+ (rad+ 20)*co, rect().center().y() - (rad + 20)*si)));
QPointF center = rect().center(); QPointF center = rect().center();
painter->drawArc(QRectF(center.x() - rad/8, center.y() - rad/8, rad / 4, rad / 4), 0 painter->drawArc(QRectF(center.x() - rad/8, center.y() - rad/8, rad / 4, rad / 4), 0
, (mCurrentAngle - (int)(mCurrentAngle/360)*360)*16); , (mCurrentAngle - (int)(mCurrentAngle/360)*360)*16);
painter->translate(rect().center()); painter->translate(rect().center());
painter->rotate(-mCurrentAngle); painter->rotate(-mCurrentAngle);
painter->translate(-rect().center().x(), -rect().center().y()); painter->translate(-rect().center().x(), -rect().center().y());
//Paint Angle text (horizontally) //Paint Angle text (horizontally)
//restore transformations //restore transformations
painter->translate(rect().center()); painter->translate(rect().center());
painter->rotate(mCurrentAngle); painter->rotate(mCurrentAngle);
painter->rotate(mStartAngle); painter->rotate(mStartAngle);
@ -495,23 +498,23 @@ 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();
font2.setBold(true); font2.setBold(true);
QFontMetricsF fm2(font2); QFontMetricsF fm2(font2);
painter->setFont(font2); painter->setFont(font2);
if (angle < 50) if (angle < 50)
angle = 90; angle = 90;
else else
angle = angle / 2; angle = angle / 2;
co = cos((mStartAngle + angle) * PI/180); co = cos((mStartAngle + angle) * PI/180);
si = sin((mStartAngle + angle) * PI/180); si = sin((mStartAngle + angle) * PI/180);
painter->drawText(QRectF(rect().center().x() + (rad*2.5/10)*co - fm2.width(ang)/2, painter->drawText(QRectF(rect().center().x() + (rad*2.5/10)*co - fm2.width(ang)/2,
rect().center().y() - (rad*2.5/10)*si - fm2.height()/2, rect().center().y() - (rad*2.5/10)*si - fm2.height()/2,
fm2.width(ang), fm2.height()), Qt::AlignTop, ang); fm2.width(ang), fm2.height()), Qt::AlignTop, ang);
} }
painter->restore(); painter->restore();
@ -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,9 +587,11 @@ 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
{ {
return QPointF(rect().x(), rect().y()); return QPointF(rect().x(), rect().y());
} }

@ -58,6 +58,7 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event);
virtual QPainterPath shape() const; virtual QPainterPath shape() const;
QRectF boundingRect() const; QRectF boundingRect() const;
private: private:
// Helpers // Helpers
void paintGraduations (QPainter *painter); void paintGraduations (QPainter *painter);
@ -90,10 +91,13 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse
QGraphicsSvgItem* mResizeSvgItem; QGraphicsSvgItem* mResizeSvgItem;
QGraphicsSvgItem* mMarkerSvgItem; QGraphicsSvgItem* mMarkerSvgItem;
static const QRectF sDefaultRect; static const QRectF sDefaultRect;
virtual void rotateAroundTopLeftOrigin(qreal angle);
virtual QPointF topLeftOrigin() const;
virtual void rotateAroundTopLeftOrigin(qreal angle); int sFillTransparency;
virtual QPointF topLeftOrigin() const; int sDrawTransparency;
}; };
#endif /* UBGRAPHICSPROTRACTOR_H_ */ #endif /* UBGRAPHICSPROTRACTOR_H_ */

Loading…
Cancel
Save