[linux] added rounding of window corners

This commit is contained in:
SimplestStudio
2023-10-12 16:54:40 +03:00
parent 4b079d7a85
commit 45f18f99dc
3 changed files with 33 additions and 1 deletions

View File

@ -124,6 +124,7 @@ void CWindowBase::updateScaling(bool resize)
void CWindowBase::setWindowColors(const QColor& background, const QColor& border)
{
Q_UNUSED(border)
setProperty("borderColor", border);
setStyleSheet(QString("QMainWindow{border:1px solid %1;"
#ifdef _WIN32
"border-bottom:2px solid %1;"

View File

@ -35,19 +35,25 @@
#include "defines.h"
#include "utils.h"
#include <QTimer>
#include <QPainter>
#include <QX11Info>
#include <xcb/xcb.h>
#ifdef DOCUMENTSCORE_OPENSSL_SUPPORT
# include "platform_linux/cdialogopenssl.h"
#endif
#define WINDOW_CORNER_RADIUS 6
CWindowPlatform::CWindowPlatform(const QRect &rect) :
CWindowBase(rect),
CX11Decoration(this)
{
if (isCustomWindowStyle())
if (isCustomWindowStyle()) {
if (QX11Info::isCompositingManagerRunning())
setAttribute(Qt::WA_TranslucentBackground);
CX11Decoration::turnOff();
}
setIsCustomWindowStyle(!CX11Decoration::isDecorated());
setFocusPolicy(Qt::StrongFocus);
setProperty("stabilized", true);
@ -145,6 +151,30 @@ void CWindowPlatform::setScreenScalingFactor(double factor, bool resize)
CWindowBase::setScreenScalingFactor(factor, resize);
}
void CWindowPlatform::paintEvent(QPaintEvent *event)
{
CWindowBase::paintEvent(event);
if (!QX11Info::isCompositingManagerRunning())
return;
QPainter pnt(this);
pnt.setRenderHint(QPainter::Antialiasing);
int d = 2 * WINDOW_CORNER_RADIUS * m_dpiRatio;
QPainterPath path;
path.moveTo(width(), d/2);
path.arcTo(width() - d, 0, d, d, 0, 90);
path.lineTo(d/2, 0);
path.arcTo(0, 0, d, d, 90, 90);
path.lineTo(0, height());
path.lineTo(width(), height());
path.lineTo(width(), d/2);
path.closeSubpath();
pnt.fillPath(path, palette().window().color());
QColor borderColor = property("borderColor").value<QColor>();
pnt.strokePath(path, QPen(borderColor, 1));
pnt.end();
}
/** Private **/
void CWindowPlatform::mouseMoveEvent(QMouseEvent *e)

View File

@ -53,6 +53,7 @@ protected:
virtual bool event(QEvent *event) override;
virtual bool nativeEvent(const QByteArray&, void*, long*) final;
virtual void setScreenScalingFactor(double, bool resize = true) override;
virtual void paintEvent(QPaintEvent *event) override;
private:
virtual void mouseMoveEvent(QMouseEvent *) final;