Decoration: Support HiDPI

pull/3/head
cutefishd 4 years ago
parent 73459ffd95
commit 06892a8c6d

@ -69,11 +69,12 @@ void Button::paint(QPainter *painter, const QRect &repaintRegion)
auto c = decoration->client().toStrongRef().data();
const bool isDarkMode = decoration->darkMode();
const QRect &rect = geometry().toRect();
painter->save();
painter->save();
painter->setRenderHints(QPainter::Antialiasing);
QRect btnRect(0, 0, 30, 30);
QRect btnRect(0, 0, 30 * decoration->devicePixelRatio(),
30 * decoration->devicePixelRatio());
btnRect.moveCenter(rect.center());
if (isHovered() || isPressed()) {

@ -31,6 +31,7 @@
#include <QPainter>
#include <QSettings>
#include <QSharedPointer>
#include <QImageReader>
#include <QTimer>
#include <KPluginFactory>
@ -112,6 +113,8 @@ void Decoration::init()
auto c = client().toStrongRef().data();
auto s = settings();
m_devicePixelRatio = m_settings->value("PixelRatio", 1.0).toReal();
reconfigure();
updateTitleBar();
@ -150,8 +153,10 @@ void Decoration::init()
// cutefishos settings
m_fileWatcher->addPath(m_settingsFile);
connect(m_fileWatcher, &QFileSystemWatcher::fileChanged, this, [=] {
updateBtnPixmap();
m_settings->sync();
m_devicePixelRatio = m_settings->value("PixelRatio", 1.0).toReal();
updateBtnPixmap();
update(titleBar());
updateTitleBar();
updateButtonsGeometry();
@ -188,11 +193,11 @@ void Decoration::recalculateBorders()
{
QMargins borders;
if (!isMaximized()) {
borders.setLeft(m_frameRadius / 2);
borders.setRight(m_frameRadius / 2);
borders.setBottom(m_frameRadius / 2);
}
// if (!isMaximized()) {
// borders.setLeft(m_frameRadius / 2);
// borders.setRight(m_frameRadius / 2);
// borders.setBottom(m_frameRadius / 2);
// }
borders.setTop(titleBarHeight());
@ -343,17 +348,19 @@ void Decoration::updateBtnPixmap()
QPixmap Decoration::fromSvgToPixmap(const QString &file, const QSize &size)
{
const qreal ratio = qApp->devicePixelRatio();
QPixmap pixmap(size * ratio);
pixmap.load(file);
pixmap.setDevicePixelRatio(ratio);
return pixmap;
QImageReader reader(file);
if (reader.canRead()) {
reader.setScaledSize(size * m_devicePixelRatio);
return QPixmap::fromImage(reader.read());
}
return QPixmap();
}
int Decoration::titleBarHeight() const
{
qreal ratio = qApp->devicePixelRatio();
return m_titleBarHeight * ratio;
return m_titleBarHeight * m_devicePixelRatio;
// const QFontMetrics fontMetrics(settings()->font());
// const int baseUnit = settings()->gridUnit();

@ -51,6 +51,7 @@ public:
QPixmap restoreBtnPixmap() { return m_restoreBtnPixmap; }
bool darkMode() const;
qreal devicePixelRatio() const { return m_devicePixelRatio; }
public slots:
void init() override;
@ -90,7 +91,8 @@ private:
private:
int m_titleBarHeight = 38;
int m_frameRadius = 0;
int m_frameRadius = 12;
qreal m_devicePixelRatio = 1.0;
QColor m_titleBarBgColor = QColor(255, 255, 255, 255);
QColor m_titleBarFgColor = QColor(56, 56, 56, 255);
QColor m_unfocusedFgColor = QColor(127, 127, 127, 255);

@ -111,8 +111,8 @@ void RoundedWindow::paintWindow(KWin::EffectWindow *w, int mask, QRegion region,
|| w->isDock()
|| w->isPopupWindow()
|| w->isPopupMenu()
// || data.quads.isTransformed()
// || (mask & (PAINT_WINDOW_TRANSFORMED|PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS))
|| data.quads.isTransformed()
|| (mask & (PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS))
|| !hasShadow(data.quads)) {
KWin::effects->paintWindow(w, mask, region, data);
return;

Loading…
Cancel
Save