Sh3/graphicsarcitem.cpp
2025-07-02 07:45:34 +03:00

94 lines
1.9 KiB
C++

#include "graphicsarcitem.h"
graphicsArcItem::graphicsArcItem(qreal x, qreal y, qreal r, qreal a1, qreal a2)
{
this->x = x;
this->y = y;
this->r = r;
this->a1 = a1;
this->a2 = a2;
this->col = QColor(Qt::black);
this->textLeft="";
this->textRight="";
this->textVisible=false;
}
QRectF graphicsArcItem::boundingRect() const
{
return QRectF(x-r, y-r, 2*r, 2*r);
}
//QPainterPath graphicsArcItem::shape() const
//{
// QPainterPath path;
// path.moveTo(x+r, y+r);
// path.arcTo(boundingRect(), a2, a1);
// return path;
//}
void graphicsArcItem::setColor(QColor c)
{
if (col!=c) {
prepareGeometryChange();
col = c;
}
}
void graphicsArcItem::setRadius(qreal rr)
{
if (r!=rr) {
prepareGeometryChange();
r = rr;
}
}
void graphicsArcItem::setAngle1(qreal a)
{
if (a1 != a) {
prepareGeometryChange();
a1=a;
}
}
void graphicsArcItem::setAngle2(qreal a)
{
if (a2 != a) {
prepareGeometryChange();
a2=a;
}
}
void graphicsArcItem::setAngles(qreal aa, qreal ab)
{
setAngle1(aa);
setAngle2(ab);
}
void graphicsArcItem::setText(QString str1, QString str2)
{
if ((textLeft!=str1)||(textRight!=str2))
{
prepareGeometryChange();
textLeft = str1;
textRight = str2;
}
}
void graphicsArcItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(QPen(col));
painter->drawPie(boundingRect(), a1*16, (a2-a1)*16);
if (textVisible)
{
qreal fs = r/223;
painter->setPen(QPen(Qt::white));
QFont f = painter->font();
f.setPointSizeF(fs*7);
painter->setFont(f);
painter->drawText(x+0.95*r*cos(a1/180*M_PI), y-0.95*r*sin(a1/180*M_PI), textLeft);
painter->drawText(x+0.95*r*cos(a2/180*M_PI), y-0.95*r*sin(a2/180*M_PI), textRight);
}
}