From e89ac584629ae5ea636bf7c3a35337b2ee08b178 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 24 Jan 2022 18:37:16 +0800 Subject: [PATCH] - enhancement: auto zoom ui when screen's zoom factor changed (windows) --- NEWS.md | 1 + RedPandaIDE/main.cpp | 5 ++++- RedPandaIDE/mainwindow.cpp | 6 ++++++ RedPandaIDE/mainwindow.h | 1 + RedPandaIDE/utils.cpp | 14 +++++++++++--- RedPandaIDE/utils.h | 2 ++ 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index fb5ae43d..72b933d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,7 @@ Red Panda C++ Version 0.13.3 - fix: insert code snippets will crash, if current compiler set's include dir list is not empty and lib dir list is empty - fix: search around option can't be disabled - enhancement: show a confirm dialog when search/replace around + - enhancement: auto zoom ui when screen's zoom factor changed (windows) Red Panda C++ Version 0.13.2 - fix: "delete and exit" button in the environtment / folder option page doesn't work correctly diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index 8121bc0f..a8bf6420 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "common.h" #include "colorscheme.h" @@ -60,7 +61,8 @@ bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray & /*eventType*/ } break; case WM_DPICHANGED: - //todo + setDesktopDpi(HIWORD(pMsg->wParam)); + pMainWindow->updateDPI(); break; } return false; @@ -159,6 +161,7 @@ int main(int argc, char *argv[]) //set default open folder QDir::setCurrent(pSettings->environment().defaultOpenFolder()); + setDesktopDpi(qApp->desktop()->logicalDpiY()); MainWindow mainWindow; pMainWindow = &mainWindow; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 22ce6e38..15929910 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -689,6 +689,12 @@ void MainWindow::setActiveBreakpoint(QString FileName, int Line, bool setFocus) } } +void MainWindow::updateDPI() +{ + qDebug()<<"dpi changed!"<desktop()->logicalDpiY() / 72; + return point * desktopDpi() / 72; } float pixelToPoint(float pixel) { - return pixel * 72 / qApp->desktop()->logicalDpiY(); + return pixel * 72 / desktopDpi(); } @@ -1076,9 +1076,12 @@ QStringList splitProcessCommand(const QString &cmd) return result; } +static float saved_desktop_dpi = -1; float desktopDpi() { - return qApp->desktop()->logicalDpiY(); + if (saved_desktop_dpi<1) + saved_desktop_dpi = qApp->desktop()->logicalDpiY(); + return saved_desktop_dpi; } qulonglong stringToHex(const QString &str, qulonglong defaultValue) @@ -1089,3 +1092,8 @@ qulonglong stringToHex(const QString &str, qulonglong defaultValue) return value; return defaultValue; } + +void setDesktopDpi(float dpi) +{ + saved_desktop_dpi = dpi; +} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index fee53bab..de920531 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -232,6 +232,8 @@ class CppParser; void resetCppParser(std::shared_ptr parser, int compilerSetIndex=-1); float desktopDpi(); +void setDesktopDpi(float dpi); + float pointToPixel(float point); float pixelToPoint(float pixel);