diff --git a/NEWS.md b/NEWS.md index 147d04d3..0b2ea371 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ Red Panda C++ Version 0.13.4 - enhancement: show parameter tips for class constructors - enhancement: when there are tips showing, don't show mouse tips - enhancement: setting non-ascii font for editors + - enhancement: correct handle windows dpi change event Red Panda C++ Version 0.13.3 - enhancement: restore editor position after rename symbol diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index a8bf6420..ad4b186b 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "common.h" #include "colorscheme.h" #include "iconsmanager.h" @@ -61,7 +62,7 @@ bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray & /*eventType*/ } break; case WM_DPICHANGED: - setDesktopDpi(HIWORD(pMsg->wParam)); + setScreenDPI(HIWORD(pMsg->wParam)); pMainWindow->updateDPI(); break; } @@ -161,8 +162,6 @@ int main(int argc, char *argv[]) //set default open folder QDir::setCurrent(pSettings->environment().defaultOpenFolder()); - setDesktopDpi(qApp->desktop()->logicalDpiY()); - MainWindow mainWindow; pMainWindow = &mainWindow; if (app.arguments().count()>1) { diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index fe85838f..b297b2eb 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -310,7 +311,7 @@ MainWindow::MainWindow(QWidget *parent) buildContextMenus(); updateAppTitle(); - applySettings(); + //applySettings(); applyUISettings(); updateProjectView(); updateEditorActions(); @@ -560,7 +561,8 @@ void MainWindow::updateEditorColorSchemes() void MainWindow::applySettings() { - //changeTheme(pSettings->environment().theme()); + qDebug()<<"--- apply settings -- "; + qDebug()<logicalDotsPerInch(); ThemeManager themeManager; PAppTheme appTheme = themeManager.theme(pSettings->environment().theme()); if (appTheme->isDark()) @@ -574,11 +576,15 @@ void MainWindow::applySettings() mFileInfoStatus->setPalette(appTheme->palette()); updateEditorColorSchemes(); + qDebug()<environment().interfaceFontSize()); QFont font(pSettings->environment().interfaceFont()); font.setPixelSize(pointToPixel(pSettings->environment().interfaceFontSize())); font.setStyleStrategy(QFont::PreferAntialias); qApp->setFont(font); this->setFont(font); + for (QWidget* p:findChildren()) { + p->setFont(font); + } pIconsManager->updateParserIcons(pSettings->environment().iconSet(),pointToPixel(pSettings->environment().interfaceFontSize())); QFont caseEditorFont(pSettings->executor().caseEditorFontName()); @@ -620,6 +626,7 @@ void MainWindow::applySettings() updateEditorSettings(); updateDebuggerSettings(); updateActionIcons(); + qDebug()<<"*** app setting ****"; } void MainWindow::applyUISettings() @@ -691,6 +698,7 @@ void MainWindow::setActiveBreakpoint(QString FileName, int Line, bool setFocus) void MainWindow::updateDPI() { + qDebug()<<"dpi changed"; applySettings(); } @@ -3739,6 +3747,8 @@ void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::showEvent(QShowEvent *) { + setScreenDPI(screen()->logicalDotsPerInch()); + applySettings(); const Settings::UI& settings = pSettings->ui(); ui->tabMessages->setCurrentIndex(settings.bottomPanelIndex()); if (settings.bottomPanelOpenned()) { diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index ebb689ca..9f397e49 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -685,6 +685,7 @@ protected: void closeEvent(QCloseEvent *event) override; void showEvent(QShowEvent* event) override; void hideEvent(QHideEvent *event) override; + }; extern MainWindow* pMainWindow; diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 10b14c9e..620b63d6 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -30,7 +30,8 @@ #include #include #include -#include +#include +#include #include "parser/cppparser.h" #include "settings.h" #include "mainwindow.h" @@ -1001,12 +1002,12 @@ QString localizePath(const QString &path) float pointToPixel(float point) { - return point * desktopDpi() / 72; + return point * screenDPI() / 72; } float pixelToPoint(float pixel) { - return pixel * 72 / desktopDpi(); + return pixel * 72 / screenDPI(); } @@ -1076,12 +1077,14 @@ QStringList splitProcessCommand(const QString &cmd) return result; } -static float saved_desktop_dpi = -1; -float desktopDpi() +static int defaultScreenDPI = -1; + +int screenDPI() { - if (saved_desktop_dpi<1) - saved_desktop_dpi = qApp->desktop()->logicalDpiY(); - return saved_desktop_dpi; + if (defaultScreenDPI<1) { + defaultScreenDPI = qApp->primaryScreen()->logicalDotsPerInch(); + } + return defaultScreenDPI; } qulonglong stringToHex(const QString &str, qulonglong defaultValue) @@ -1093,7 +1096,7 @@ qulonglong stringToHex(const QString &str, qulonglong defaultValue) return defaultValue; } -void setDesktopDpi(float dpi) +void setScreenDPI(int dpi) { - saved_desktop_dpi = dpi; + defaultScreenDPI = dpi; } diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index de920531..a63b0668 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -231,9 +231,8 @@ bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QSt class CppParser; void resetCppParser(std::shared_ptr parser, int compilerSetIndex=-1); -float desktopDpi(); -void setDesktopDpi(float dpi); - +int screenDPI(); +void setScreenDPI(int dpi); float pointToPixel(float point); float pixelToPoint(float pixel); diff --git a/RedPandaIDE/widgets/darkfusionstyle.cpp b/RedPandaIDE/widgets/darkfusionstyle.cpp index 65f0fc4e..7618c9e3 100644 --- a/RedPandaIDE/widgets/darkfusionstyle.cpp +++ b/RedPandaIDE/widgets/darkfusionstyle.cpp @@ -87,7 +87,7 @@ static QString uniqueName(const QString &key, const QStyleOption *option, const } static qreal calcDpi() { - return desktopDpi(); + return screenDPI(); } static qreal calcDpiScaled(qreal value, qreal dpi) {