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

Method paintRadiusDisplay

src/tools/UBGraphicsCompass.cpp:527–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525}
526
527void UBGraphicsCompass::paintRadiusDisplay(QPainter *painter)
528{
529 double pixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize();
530
531 qreal radiusInCentimeters = rect().width() / pixelsPerCentimeter;
532 QString format = rect().width() >= sDisplayRadiusUnitMinLength ? "%1 cm" : "%1";
533 QString radiusText = QString(format).arg(radiusInCentimeters, 0, 'f', 1);
534
535 bool onPencilArm = rect().width() > sDisplayRadiusOnPencilArmMinLength;
536
537 painter->save();
538 painter->setFont(font());
539 QFontMetricsF fm(painter->font());
540 QPointF textCenter;
541
542 if (onPencilArm)
543 textCenter = QPointF(rect().right() - sPencilBaseLength - sPencilLength - fm.horizontalAdvance(radiusText) / 2 - 24 - 8, rect().center().y());
544 else
545 textCenter = QPointF((rect().left() + sNeedleLength + sNeedleBaseLength + hingeRect().left()) / 2, rect().center().y());
546
547 painter->translate(textCenter);
548 qreal angle = angleInDegrees();
549 if (angle > 180)
550 angle -= 360;
551 else if (angle < -180)
552 angle += 360;
553 if (angle <= -90 || angle > 90)
554 painter->rotate(180);
555 painter->drawText(
556 QRectF(
557 - fm.horizontalAdvance(radiusText) / 2,
558 - rect().height() / 2,
559 fm.horizontalAdvance(radiusText),
560 rect().height()),
561 Qt::AlignVCenter,
562 radiusText);
563 painter->restore();
564}
565
566QCursor UBGraphicsCompass::moveCursor() const
567{

Callers

nothing calls this directly

Calls 6

backgroundGridSizeMethod · 0.80
activeSceneMethod · 0.80
widthMethod · 0.45
saveMethod · 0.45
fontMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected