75void QQuickBasicDial::paint(QPainter *painter)
77 if (width() <= 0 || height() <= 0)
82 pen.setCapStyle(Qt::FlatCap);
85 const QRectF bounds = boundingRect();
86 const qreal smallest = qMin(bounds.width(), bounds.height());
87 QRectF rect = QRectF(pen.widthF() / 2.0 + 1, pen.widthF() / 2.0 + 1, smallest - pen.widthF() - 2, smallest - pen.widthF() - 2);
88 rect.moveCenter(bounds.center());
91 if (rect.x() -
int(rect.x()) > 0)
92 rect.setX(qCeil(rect.x()));
93 if (rect.y() -
int(rect.y()) > 0)
94 rect.setY(qCeil(rect.y()));
95 if (rect.width() -
int(rect.width()) > 0)
96 rect.setWidth(qFloor(rect.width()));
97 if (rect.height() -
int(rect.height()) > 0)
98 rect.setHeight(qFloor(rect.height()));
100 painter->setRenderHint(QPainter::Antialiasing);
102 const qreal startAngle = 90. - m_startAngle;
103 const qreal spanAngle = m_progress * (m_startAngle - m_endAngle);
105 path.arcMoveTo(rect, startAngle);
106 path.arcTo(rect, startAngle, spanAngle);
107 painter->drawPath(path);
109 rect.adjust(-pen.widthF() / 2.0, -pen.widthF() / 2.0, pen.widthF() / 2.0, pen.widthF() / 2.0);
111 painter->setPen(pen);
113 path = QPainterPath();
114 path.arcMoveTo(rect, 0);
115 path.arcTo(rect, 0, 360);
116 painter->drawPath(path);