2023-09-17 20:36:33 +08:00
|
|
|
#include "FluRectangle.h"
|
|
|
|
#include <QPainterPath>
|
|
|
|
|
2024-04-11 14:51:43 +08:00
|
|
|
FluRectangle::FluRectangle(QQuickItem *parent) : QQuickPaintedItem(parent) {
|
|
|
|
color(QColor(255, 255, 255, 255));
|
|
|
|
radius({0, 0, 0, 0});
|
|
|
|
connect(this, &FluRectangle::colorChanged, this, [=] { update(); });
|
|
|
|
connect(this, &FluRectangle::radiusChanged, this, [=] { update(); });
|
2023-09-17 20:36:33 +08:00
|
|
|
}
|
|
|
|
|
2024-04-11 14:51:43 +08:00
|
|
|
void FluRectangle::paint(QPainter *painter) {
|
2023-09-17 20:36:33 +08:00
|
|
|
painter->save();
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
|
|
QPainterPath path;
|
|
|
|
QRectF rect = boundingRect();
|
|
|
|
path.moveTo(rect.bottomRight() - QPointF(0, _radius[2]));
|
|
|
|
path.lineTo(rect.topRight() + QPointF(0, _radius[1]));
|
|
|
|
path.arcTo(QRectF(QPointF(rect.topRight() - QPointF(_radius[1] * 2, 0)), QSize(_radius[1] * 2, _radius[1] * 2)), 0, 90);
|
|
|
|
path.lineTo(rect.topLeft() + QPointF(_radius[0], 0));
|
|
|
|
path.arcTo(QRectF(QPointF(rect.topLeft()), QSize(_radius[0] * 2, _radius[0] * 2)), 90, 90);
|
|
|
|
path.lineTo(rect.bottomLeft() - QPointF(0, _radius[3]));
|
|
|
|
path.arcTo(QRectF(QPointF(rect.bottomLeft() - QPointF(0, _radius[3] * 2)), QSize(_radius[3] * 2, _radius[3] * 2)), 180, 90);
|
2023-09-22 17:35:02 +08:00
|
|
|
path.lineTo(rect.bottomRight() - QPointF(_radius[2], 0));
|
2023-09-17 20:36:33 +08:00
|
|
|
path.arcTo(QRectF(QPointF(rect.bottomRight() - QPointF(_radius[2] * 2, _radius[2] * 2)), QSize(_radius[2] * 2, _radius[2] * 2)), 270, 90);
|
2024-04-11 14:51:43 +08:00
|
|
|
painter->fillPath(path, _color);
|
2023-09-17 20:36:33 +08:00
|
|
|
painter->restore();
|
|
|
|
}
|