MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / paintGraduations

Method paintGraduations

src/tools/UBGraphicsProtractor.cpp:454–519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

452}
453
454void UBGraphicsProtractor::paintGraduations(QPainter *painter)
455{
456 painter->save();
457
458 const int tenDegreeGraduationLength = 22;
459 const int fiveDegreeGraduationLength = 15;
460 const int oneDegreeGraduationLength = 7;
461
462 QFont font1 = painter->font();
463
464#ifdef Q_OS_OSX
465 font1.setPointSizeF(font1.pointSizeF() + 3);
466 font1.setWeight(QFont::Thin);
467#endif
468 QFontMetricsF fm1(font1);
469
470 //Font for internal arc
471 QFont font2 = painter->font();
472 font2.setPointSizeF(font1.pointSizeF()/1.5);
473 QFontMetricsF fm2(font2);
474
475 qreal rad = radius();
476
477 QPointF center = rect().center();
478 painter->drawArc(QRectF(center.x() - rad/2, center.y() - rad/2, rad, rad), mStartAngle*16, mSpan*16);
479
480 for (int angle = 1; angle < mSpan; angle++)
481 {
482 int graduationLength = (0 == angle % 10) ? tenDegreeGraduationLength : ((0 == angle % 5) ? fiveDegreeGraduationLength : oneDegreeGraduationLength);
483 qreal co = cos(((qreal)angle + mStartAngle) * PI/180);
484 qreal si = sin(((qreal)angle + mStartAngle) * PI/180);
485 if (0 == angle % 90)
486 painter->drawLine(QLineF(QPointF(center.x(), center.y()),
487 QPointF(center.x() + co*tenDegreeGraduationLength, center.y() - si*tenDegreeGraduationLength)));
488
489 //external arc
490 painter->drawLine(QLineF(QPointF(center.x()+ rad*co, center.y() - rad*si),
491 QPointF(center.x()+ (rad - graduationLength)*co, center.y() - (rad - graduationLength)*si)));
492 //internal arc
493 painter->drawLine(QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si),
494 QPointF(center.x()+ (rad/2 + graduationLength)*co,
495 center.y() - (rad/2 + graduationLength)*si)));
496
497 if (0 == angle % 10)
498 {
499 //external arc
500 painter->setFont(font1);
501 QString grad = QString("%1").arg((int)(angle));
502 QString grad2 = QString("%1").arg((int)(mSpan - angle));
503
504 painter->drawText(QRectF(center.x() + (rad - graduationLength*1.5)*co - fm1.horizontalAdvance(grad)/2,
505 center.y() - (rad - graduationLength*1.5)*si - fm1.height()/2,
506 fm1.horizontalAdvance(grad), fm1.height()), Qt::AlignTop, grad);
507
508 //internal arc
509 painter->setFont(font2);
510 painter->drawText(QRectF(center.x() + (rad/2 + graduationLength*1.5)*co - fm2.horizontalAdvance(grad2)/2,
511 center.y() - (rad/2 + graduationLength*1.5)*si - fm2.height()/2,

Callers

nothing calls this directly

Calls 7

pointSizeFMethod · 0.80
drawArcMethod · 0.80
cosFunction · 0.50
sinFunction · 0.50
saveMethod · 0.45
fontMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected