Added util to generate path of complex rounded rect.
This commit is contained in:
parent
fd55e9b71b
commit
70867536a4
2 changed files with 58 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue