yacreader/custom_widgets/rounded_corners_dialog.cpp
Luis Ángel San Martín 9c0aa41c32 Improve what's new style
2022-07-06 10:06:22 +02:00

38 lines
1014 B
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::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()));
// 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();
}