From 43d0e5f95d61af8a0d8e4570c791c84741fc4e3e Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sun, 21 Mar 2021 20:38:33 +0800 Subject: [PATCH] Minor tweaks Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- qtacryliceffecthelper.cpp | 22 +++++++++------------- utilities.cpp | 22 ++++++++++++++++++++++ utilities.h | 7 +++++-- utilities_win32.cpp | 12 ++++++------ 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/qtacryliceffecthelper.cpp b/qtacryliceffecthelper.cpp index fe5e9a5..1c16d32 100644 --- a/qtacryliceffecthelper.cpp +++ b/qtacryliceffecthelper.cpp @@ -227,12 +227,7 @@ void QtAcrylicEffectHelper::paintBackground(QPainter *painter, const QRect &rect } else { // Emulate blur behind window by blurring the desktop wallpaper. updateBehindWindowBackground(); - QPoint point = m_window->mapToGlobal(QPoint{0, 0}); - const QRect geometry = Utilities::getScreenAvailableGeometry(m_window); - if (geometry.isValid()) { - point -= geometry.topLeft(); - } - painter->drawPixmap(QPoint{0, 0}, m_bluredWallpaper, QRect{point, rect.size()}); + painter->drawPixmap(QPoint{0, 0}, m_bluredWallpaper, QRect{m_window->mapToGlobal(QPoint{0, 0}), rect.size()}); } painter->setCompositionMode(QPainter::CompositionMode_SourceOver); painter->setOpacity(1); @@ -310,7 +305,7 @@ void QtAcrylicEffectHelper::updateBehindWindowBackground() if (!m_bluredWallpaper.isNull()) { return; } - const QSize size = Utilities::getScreenAvailableGeometry(m_window).size(); + const QSize size = Utilities::getScreenGeometry(m_window).size(); m_bluredWallpaper = QPixmap(size); m_bluredWallpaper.fill(Qt::transparent); QImage image = Utilities::getDesktopWallpaperImage(); @@ -321,17 +316,18 @@ void QtAcrylicEffectHelper::updateBehindWindowBackground() const Utilities::DesktopWallpaperAspectStyle aspectStyle = Utilities::getDesktopWallpaperAspectStyle(); QImage buffer(size, QImage::Format_ARGB32_Premultiplied); #ifdef Q_OS_WINDOWS - if (aspectStyle == Utilities::DesktopWallpaperAspectStyle::Central) { + if ((aspectStyle == Utilities::DesktopWallpaperAspectStyle::Central) || + (aspectStyle == Utilities::DesktopWallpaperAspectStyle::KeepRatioFit)) { buffer.fill(Utilities::getDesktopBackgroundColor()); } #endif - if (aspectStyle == Utilities::DesktopWallpaperAspectStyle::IgnoreRatioFill || - aspectStyle == Utilities::DesktopWallpaperAspectStyle::KeepRatioFill || + if (aspectStyle == Utilities::DesktopWallpaperAspectStyle::IgnoreRatioFit || + aspectStyle == Utilities::DesktopWallpaperAspectStyle::KeepRatioFit || aspectStyle == Utilities::DesktopWallpaperAspectStyle::KeepRatioByExpanding) { - Qt::AspectRatioMode mode = Qt::KeepAspectRatioByExpanding; - if (aspectStyle == Utilities::DesktopWallpaperAspectStyle::IgnoreRatioFill) { + Qt::AspectRatioMode mode; + if (aspectStyle == Utilities::DesktopWallpaperAspectStyle::IgnoreRatioFit) { mode = Qt::IgnoreAspectRatio; - } else if (aspectStyle == Utilities::DesktopWallpaperAspectStyle::KeepRatioFill) { + } else if (aspectStyle == Utilities::DesktopWallpaperAspectStyle::KeepRatioFit) { mode = Qt::KeepAspectRatio; } else { mode = Qt::KeepAspectRatioByExpanding; diff --git a/utilities.cpp b/utilities.cpp index 736c265..628d1d1 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -487,3 +487,25 @@ QRect Utilities::getScreenAvailableGeometry(const QPoint &pos) } return QGuiApplication::primaryScreen()->availableGeometry(); } + +QRect Utilities::getScreenGeometry(const QWindow *window) +{ + if (window) { + const QScreen *screen = window->screen(); + if (screen) { + return screen->geometry(); + } + } + return QGuiApplication::primaryScreen()->geometry(); +} + +QRect Utilities::getScreenGeometry(const QPoint &pos) +{ + if (!pos.isNull()) { + const QScreen *screen = QGuiApplication::screenAt(pos); + if (screen) { + return screen->geometry(); + } + } + return QGuiApplication::primaryScreen()->geometry(); +} diff --git a/utilities.h b/utilities.h index 92dca66..000205b 100644 --- a/utilities.h +++ b/utilities.h @@ -41,8 +41,8 @@ enum class DesktopWallpaperAspectStyle { Central, Tiled, - IgnoreRatioFill, // Stretch - KeepRatioFill, // Fit + IgnoreRatioFit, // Stretch + KeepRatioFit, // Fit KeepRatioByExpanding, // Fill Span // Span }; @@ -66,6 +66,9 @@ FRAMELESSHELPER_EXPORT DesktopWallpaperAspectStyle getDesktopWallpaperAspectStyl FRAMELESSHELPER_EXPORT QRect getScreenAvailableGeometry(const QWindow *window); FRAMELESSHELPER_EXPORT QRect getScreenAvailableGeometry(const QPoint &pos); +FRAMELESSHELPER_EXPORT QRect getScreenGeometry(const QWindow *window); +FRAMELESSHELPER_EXPORT QRect getScreenGeometry(const QPoint &pos); + FRAMELESSHELPER_EXPORT QRect alignedRect(const Qt::LayoutDirection direction, const Qt::Alignment alignment, const QSize &size, const QRect &rectangle); FRAMELESSHELPER_EXPORT void blurImage(QImage &blurImage, const qreal radius, const bool quality, const int transposed = 0); diff --git a/utilities_win32.cpp b/utilities_win32.cpp index 35178fa..7472f58 100644 --- a/utilities_win32.cpp +++ b/utilities_win32.cpp @@ -623,9 +623,9 @@ Utilities::DesktopWallpaperAspectStyle Utilities::getDesktopWallpaperAspectStyle case DWPOS_TILE: return DesktopWallpaperAspectStyle::Tiled; case DWPOS_STRETCH: - return DesktopWallpaperAspectStyle::IgnoreRatioFill; + return DesktopWallpaperAspectStyle::IgnoreRatioFit; case DWPOS_FIT: - return DesktopWallpaperAspectStyle::KeepRatioFill; + return DesktopWallpaperAspectStyle::KeepRatioFit; case DWPOS_FILL: return DesktopWallpaperAspectStyle::KeepRatioByExpanding; case DWPOS_SPAN: @@ -663,9 +663,9 @@ Utilities::DesktopWallpaperAspectStyle Utilities::getDesktopWallpaperAspectStyle case WPSTYLE_TILE: return DesktopWallpaperAspectStyle::Tiled; case WPSTYLE_STRETCH: - return DesktopWallpaperAspectStyle::IgnoreRatioFill; + return DesktopWallpaperAspectStyle::IgnoreRatioFit; case WPSTYLE_KEEPASPECT: - return DesktopWallpaperAspectStyle::KeepRatioFill; + return DesktopWallpaperAspectStyle::KeepRatioFit; case WPSTYLE_CROPTOFIT: return DesktopWallpaperAspectStyle::KeepRatioByExpanding; case WPSTYLE_SPAN: @@ -698,9 +698,9 @@ Utilities::DesktopWallpaperAspectStyle Utilities::getDesktopWallpaperAspectStyle } } case 2: - return DesktopWallpaperAspectStyle::IgnoreRatioFill; + return DesktopWallpaperAspectStyle::IgnoreRatioFit; case 6: - return DesktopWallpaperAspectStyle::KeepRatioFill; + return DesktopWallpaperAspectStyle::KeepRatioFit; case 10: return DesktopWallpaperAspectStyle::KeepRatioByExpanding; case 22: