Files
yacreader/custom_widgets/rounded_corners_dialog.cpp
2026-02-19 18:06:32 +01:00

45 lines
1.2 KiB
C++

#include "rounded_corners_dialog.h"
#include <QtWidgets>
YACReader::RoundedCornersDialog::RoundedCornersDialog(QWidget *parent)
: QDialog(parent)
{
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
setAttribute(Qt::WA_TranslucentBackground);
}
void YACReader::RoundedCornersDialog::setBackgroundColor(const QColor &color)
{
m_backgroundColor = color;
update();
}
void YACReader::RoundedCornersDialog::paintEvent(QPaintEvent *)
{
qreal radius = 14.0; // desired radius in absolute pixels
if (!(windowFlags() & Qt::FramelessWindowHint) && !testAttribute(Qt::WA_TranslucentBackground))
return; // nothing to do
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
// Paint thyself.
QRectF rect(QPointF(0, 0), size());
p.setPen(Qt::NoPen);
// Set the brush from palette role.
// p.setBrush(palette().brush(backgroundRole()));
p.setBrush(QBrush(m_backgroundColor));
// Got radius? Otherwise draw a quicker rect.
if (radius > 0.0)
p.drawRoundedRect(rect, radius, radius, Qt::AbsoluteSize);
else
p.drawRect(rect);
// C'est finí
p.end();
}