Kylin/Fluent/Rectangle.cpp

53 lines
1.7 KiB
C++
Raw Normal View History

2024-08-20 23:58:02 +08:00
#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();
}
2024-08-21 23:26:43 +08:00
QColor Rectangle::color() const {
return m_color;
}
void Rectangle::setColor(const QColor &color) {
if (m_color != color) {
m_color = color;
emit colorChanged();
}
}
QList<int> Rectangle::radius() const {
return m_radius;
}
void Rectangle::setRadius(const QList<int> &radius) {
if (m_radius != radius) {
m_radius = radius;
emit radiusChanged();
}
}