Compass: replaced hard-coded constants in drawing methods

The size of the various parts of the compass can now be easily modified
preferencesAboutTextFull
Craig Watson 9 years ago
parent dd24e3ada3
commit e9398f55ee
  1. 100
      src/tools/UBGraphicsCompass.cpp
  2. 18
      src/tools/UBGraphicsCompass.h

@ -144,7 +144,7 @@ void UBGraphicsCompass::paint(QPainter *painter, const QStyleOptionGraphicsItem
resizeButtonRect().center().y() - mResizeSvgItem->boundingRect().height() * mAntiScaleRatio / 2); resizeButtonRect().center().y() - mResizeSvgItem->boundingRect().height() * mAntiScaleRatio / 2);
painter->setPen(drawColor()); painter->setPen(drawColor());
painter->drawRoundedRect(hingeRect(), 4, 4); painter->drawRoundedRect(hingeRect(), sCornerRadius, sCornerRadius);
painter->fillPath(hingeShape(), middleFillColor()); painter->fillPath(hingeShape(), middleFillColor());
painter->fillPath(needleShape(), middleFillColor()); painter->fillPath(needleShape(), middleFillColor());
@ -615,28 +615,30 @@ QPainterPath UBGraphicsCompass::needleShape() const
{ {
QPainterPath path; QPainterPath path;
path.moveTo(rect().left(), rect().center().y()); path.moveTo(rect().left(), rect().center().y());
path.lineTo(rect().left() + sNeedleLength, rect().center().y() - 2); path.lineTo(rect().left() + sNeedleLength, rect().center().y() - sNeedleWidth/2);
path.lineTo(rect().left() + sNeedleLength, rect().center().y() + 2); path.lineTo(rect().left() + sNeedleLength, rect().center().y() + sNeedleWidth/2);
path.closeSubpath(); path.closeSubpath();
return path; return path;
} }
QPainterPath UBGraphicsCompass::needleBaseShape() const QPainterPath UBGraphicsCompass::needleBaseShape() const
{ {
int smallHalfSide = sNeedleBaseWidth/2 - sCornerRadius;
QPainterPath path; QPainterPath path;
path.moveTo(rect().left() + sNeedleLength, rect().center().y() - 4); path.moveTo(rect().left() + sNeedleLength, rect().center().y() - smallHalfSide);
path.arcTo( path.arcTo(
rect().left() + sNeedleLength, rect().left() + sNeedleLength,
rect().center().y() - 8, rect().center().y() - smallHalfSide - sCornerRadius,
8, 8, sCornerRadius*2, sCornerRadius*2,
180, -90); 180, -90);
path.lineTo(rect().left() + sNeedleLength + sNeedleBaseLength, rect().center().y() - 8); path.lineTo(rect().left() + sNeedleLength + sNeedleBaseLength, rect().center().y() - sNeedleBaseWidth/2);
path.lineTo(rect().left() + sNeedleLength + sNeedleBaseLength, rect().center().y() + 8); path.lineTo(rect().left() + sNeedleLength + sNeedleBaseLength, rect().center().y() + sNeedleBaseWidth/2);
path.lineTo(rect().left() + sNeedleLength + 4, rect().center().y() + 8); path.lineTo(rect().left() + sNeedleLength + sCornerRadius, rect().center().y() + smallHalfSide + sCornerRadius);
path.arcTo( path.arcTo(
rect().left() + sNeedleLength, rect().left() + sNeedleLength,
rect().center().y(), rect().center().y() + smallHalfSide - sCornerRadius,
8, 8, sCornerRadius*2, sCornerRadius*2,
-90, -90); -90, -90);
path.closeSubpath(); path.closeSubpath();
@ -645,20 +647,22 @@ QPainterPath UBGraphicsCompass::needleBaseShape() const
QPainterPath UBGraphicsCompass::needleArmShape() const QPainterPath UBGraphicsCompass::needleArmShape() const
{ {
int smallHalfSide = sNeedleArmLeftWidth/2 - sCornerRadius;
QPainterPath path; QPainterPath path;
path.moveTo(rect().left() + sNeedleLength + sNeedleBaseLength, rect().center().y() - 8); path.moveTo(rect().left() + sNeedleLength + sNeedleBaseLength, rect().center().y() - smallHalfSide);
path.arcTo( path.arcTo(
rect().left() + sNeedleLength + sNeedleBaseLength, rect().left() + sNeedleLength + sNeedleBaseLength,
rect().center().y() - 12, rect().center().y() - sNeedleArmLeftWidth/2,
8, 8, sCornerRadius*2, sCornerRadius*2,
180, -90); 180, -90);
path.lineTo(hingeRect().left(), rect().center().y() - 16); path.lineTo(hingeRect().left(), rect().center().y() - sNeedleArmRigthWidth/2);
path.lineTo(hingeRect().left(), rect().center().y() + 16); path.lineTo(hingeRect().left(), rect().center().y() + sNeedleArmRigthWidth/2);
path.lineTo(rect().left() + sNeedleLength + sNeedleBaseLength + 4, rect().center().y() + 12); path.lineTo(rect().left() + sNeedleLength + sNeedleBaseLength + sCornerRadius, rect().center().y() + sNeedleArmLeftWidth/2);
path.arcTo( path.arcTo(
rect().left() + sNeedleLength + sNeedleBaseLength, rect().left() + sNeedleLength + sNeedleBaseLength,
rect().center().y() + 4, rect().center().y() + smallHalfSide - sCornerRadius,
8, 8, sCornerRadius*2, sCornerRadius*2,
-90, -90); -90, -90);
path.closeSubpath(); path.closeSubpath();
return path; return path;
@ -667,30 +671,30 @@ QPainterPath UBGraphicsCompass::needleArmShape() const
QPainterPath UBGraphicsCompass::hingeShape() const QPainterPath UBGraphicsCompass::hingeShape() const
{ {
QPainterPath path; QPainterPath path;
path.moveTo(hingeRect().left() + 4, hingeRect().top()); path.moveTo(hingeRect().left() + sCornerRadius, hingeRect().top());
path.lineTo(hingeRect().right() - 4, hingeRect().top()); path.lineTo(hingeRect().right() - sCornerRadius, hingeRect().top());
path.arcTo( path.arcTo(
hingeRect().right() - 8, hingeRect().right() - sCornerRadius*2,
hingeRect().top(), hingeRect().top(),
8, 8, sCornerRadius*2, sCornerRadius*2,
90, -90); 90, -90);
path.lineTo(hingeRect().right(), hingeRect().bottom() - 4); path.lineTo(hingeRect().right(), hingeRect().bottom() - sCornerRadius);
path.arcTo( path.arcTo(
hingeRect().right() - 8, hingeRect().right() - sCornerRadius*2,
hingeRect().bottom() - 8, hingeRect().bottom() - sCornerRadius*2,
8, 8, sCornerRadius*2, sCornerRadius*2,
0, -90); 0, -90);
path.lineTo(hingeRect().left() + 4, hingeRect().bottom()); path.lineTo(hingeRect().left() + sCornerRadius, hingeRect().bottom());
path.arcTo( path.arcTo(
hingeRect().left(), hingeRect().left(),
hingeRect().bottom() - 8, hingeRect().bottom() - sCornerRadius*2,
8, 8, sCornerRadius*2, sCornerRadius*2,
-90, -90); -90, -90);
path.lineTo(hingeRect().left(), hingeRect().top() + 4); path.lineTo(hingeRect().left(), hingeRect().top() + sCornerRadius);
path.arcTo( path.arcTo(
hingeRect().left(), hingeRect().left(),
hingeRect().top(), hingeRect().top(),
8, 8, sCornerRadius*2, sCornerRadius*2,
-180, -90); -180, -90);
path.closeSubpath(); path.closeSubpath();
return path; return path;
@ -713,18 +717,18 @@ QPainterPath UBGraphicsCompass::pencilShape() const
QPainterPath UBGraphicsCompass::pencilBaseShape() const QPainterPath UBGraphicsCompass::pencilBaseShape() const
{ {
QPainterPath path; QPainterPath path;
path.moveTo(rect().right() - sPencilLength - sPencilBaseLength, rect().center().y() - 8); path.moveTo(rect().right() - sPencilLength - sPencilBaseLength, rect().center().y() - sPencilBaseWidth/2);
path.lineTo(rect().right() - sPencilLength - 4, rect().center().y() - 8); path.lineTo(rect().right() - sPencilLength - sCornerRadius, rect().center().y() - sPencilBaseWidth/2);
path.arcTo( path.arcTo(
rect().right() - sPencilLength - 8, rect().center().y() - 8, rect().right() - sPencilLength - sCornerRadius*2, rect().center().y() - sPencilBaseWidth/2,
8, 8, sCornerRadius*2, sCornerRadius*2,
90, -90); 90, -90);
path.lineTo(rect().right() - sPencilLength, rect().center().y() + 4); path.lineTo(rect().right() - sPencilLength, rect().center().y() + sPencilBaseWidth/2 - sCornerRadius);
path.arcTo( path.arcTo(
rect().right() - sPencilLength - 8, rect().center().y(), rect().right() - sPencilLength - sCornerRadius*2, rect().center().y() + sPencilBaseWidth/2 - sCornerRadius*2,
8, 8, sCornerRadius*2, sCornerRadius*2,
0, -90); 0, -90);
path.lineTo(rect().right() - sPencilLength - sPencilBaseLength, rect().center().y() + 8); path.lineTo(rect().right() - sPencilLength - sPencilBaseLength, rect().center().y() + sPencilBaseWidth/2);
path.closeSubpath(); path.closeSubpath();
return path; return path;
@ -733,18 +737,18 @@ QPainterPath UBGraphicsCompass::pencilBaseShape() const
QPainterPath UBGraphicsCompass::pencilArmShape() const QPainterPath UBGraphicsCompass::pencilArmShape() const
{ {
QPainterPath path; QPainterPath path;
path.moveTo(hingeRect().right(), rect().center().y() - 16); path.moveTo(hingeRect().right(), rect().center().y() - sPencilArmLeftWidth/2);
path.lineTo(rect().right() - sPencilLength - sPencilBaseLength - 4, rect().center().y() - 12); path.lineTo(rect().right() - sPencilLength - sPencilBaseLength - sCornerRadius, rect().center().y() - sPencilArmRightWidth/2);
path.arcTo( path.arcTo(
rect().right() - sPencilLength - sPencilBaseLength - 8, rect().center().y() - 12, rect().right() - sPencilLength - sPencilBaseLength - sCornerRadius*2, rect().center().y() - sPencilArmRightWidth/2,
8, 8, sCornerRadius*2, sCornerRadius*2,
90, -90); 90, -90);
path.lineTo(rect().right() - sPencilLength - sPencilBaseLength, rect().center().y() + 8); path.lineTo(rect().right() - sPencilLength - sPencilBaseLength, rect().center().y() + sPencilArmRightWidth/2 - sCornerRadius);
path.arcTo( path.arcTo(
rect().right() - sPencilLength - sPencilBaseLength - 8, rect().center().y() + 4, rect().right() - sPencilLength - sPencilBaseLength - sCornerRadius*2, rect().center().y() + sPencilArmRightWidth/2 - sCornerRadius*2,
8, 8, sCornerRadius*2, sCornerRadius*2,
0, -90); 0, -90);
path.lineTo(hingeRect().right(), rect().center().y() + 16); path.lineTo(hingeRect().right(), rect().center().y() + sPencilArmLeftWidth/2);
path.closeSubpath(); path.closeSubpath();
return path; return path;
} }

@ -124,11 +124,27 @@ class UBGraphicsCompass: public QObject, public QGraphicsRectItem, public UBItem
int mPixelsPerMillimeter; int mPixelsPerMillimeter;
// Constants // Constants
static const QRect sDefaultRect;
static const int sNeedleLength = 24; static const int sNeedleLength = 24;
static const int sNeedleWidth = 4;
static const int sNeedleBaseLength = 16; static const int sNeedleBaseLength = 16;
static const int sNeedleBaseWidth = 16;
static const int sNeedleArmLeftWidth = 24;
static const int sNeedleArmRigthWidth = 32;
static const int sPencilLength = 16; static const int sPencilLength = 16;
static const int sPencilWidth = 4;
static const int sPencilBaseLength = 24; static const int sPencilBaseLength = 24;
static const int sPencilBaseWidth = 16;
static const int sPencilArmLeftWidth = 32;
static const int sPencilArmRightWidth = 24;
static const int sCornerRadius = 4;
static const QRect sDefaultRect;
static const int sMinRadius; static const int sMinRadius;
static const int sDegreeToQtAngleUnit = 16; static const int sDegreeToQtAngleUnit = 16;
static const int sFillTransparency = 127; static const int sFillTransparency = 127;

Loading…
Cancel
Save