Kylin/Fluent/Rectangle.cpp
2024-08-20 23:58:02 +08:00

31 lines
1.3 KiB
C++

#include "Rectangle.h"
#include <QPainter>
#include <QPainterPath>
Rectangle::Rectangle(QQuickItem *parent) : QQuickPaintedItem{parent} {
}
void Rectangle::paint(QPainter *painter) {
if (m_radius.size() < 4) return;
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
QPainterPath path;
QRectF rect = boundingRect();
path.moveTo(rect.bottomRight() - QPointF(0, m_radius[2]));
path.lineTo(rect.topRight() + QPointF(0, m_radius[1]));
path.arcTo(QRectF(QPointF(rect.topRight() - QPointF(m_radius[1] * 2, 0)), QSize(m_radius[1] * 2, m_radius[1] * 2)),
0, 90);
path.lineTo(rect.topLeft() + QPointF(m_radius[0], 0));
path.arcTo(QRectF(QPointF(rect.topLeft()), QSize(m_radius[0] * 2, m_radius[0] * 2)), 90, 90);
path.lineTo(rect.bottomLeft() - QPointF(0, m_radius[3]));
path.arcTo(
QRectF(QPointF(rect.bottomLeft() - QPointF(0, m_radius[3] * 2)), QSize(m_radius[3] * 2, m_radius[3] * 2)), 180,
90);
path.lineTo(rect.bottomRight() - QPointF(m_radius[2], 0));
path.arcTo(QRectF(QPointF(rect.bottomRight() - QPointF(m_radius[2] * 2, m_radius[2] * 2)),
QSize(m_radius[2] * 2, m_radius[2] * 2)),
270, 90);
painter->fillPath(path, m_color);
painter->restore();
}