Added util to generate path of complex rounded rect.

This commit is contained in:
23rd 2023-08-14 21:15:33 +03:00
parent fd55e9b71b
commit 70867536a4
2 changed files with 58 additions and 0 deletions

View file

@ -10,8 +10,59 @@
#include "ui/image/image_prepare.h"
#include "ui/ui_utility.h"
#include <QPainterPath>
namespace Ui {
QPainterPath ComplexRoundedRectPath(
const QRect &rect,
int topLeftRadius,
int topRightRadius,
int bottomLeftRadius,
int bottomRightRadius) {
auto path = QPainterPath();
path.setFillRule(Qt::WindingFill);
const auto cornerPartSize = rect.size() / 4 * 3;
const auto cornerPartOffset = QPoint(
rect.width() - cornerPartSize.width(),
rect.height() - cornerPartSize.height());
path.addRoundedRect(
rect.x(),
rect.y(),
cornerPartSize.width(),
cornerPartSize.height(),
topLeftRadius,
topLeftRadius);
path.addRoundedRect(
rect.x() + cornerPartOffset.x(),
rect.y(),
cornerPartSize.width(),
cornerPartSize.height(),
topRightRadius,
topRightRadius);
path.addRoundedRect(
rect.x(),
rect.y() + cornerPartOffset.y(),
cornerPartSize.width(),
cornerPartSize.height(),
bottomLeftRadius,
bottomLeftRadius);
path.addRoundedRect(
rect.x() + cornerPartOffset.x(),
rect.y() + cornerPartOffset.y(),
cornerPartSize.width(),
cornerPartSize.height(),
bottomRightRadius,
bottomRightRadius);
return path.simplified();
}
void DrawRoundedRect(
QPainter &p,
const QRect &rect,

View file

@ -14,6 +14,13 @@ class QPainter;
namespace Ui {
[[nodiscard]] QPainterPath ComplexRoundedRectPath(
const QRect &rect,
int topLeftRadius,
int topRightRadius,
int bottomLeftRadius,
int bottomRightRadius);
void DrawRoundedRect(
QPainter &p,
const QRect &rect,