From 770f0485b037e4f4fa7e9a885710d5318a3cd39e Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 1 Dec 2024 08:54:31 +0800 Subject: [PATCH] - enhancement: Auto scale the main ui & choose theme dialog at the first run. --- NEWS.md | 3 ++- RedPandaIDE/mainwindow.cpp | 11 +++++++++++ RedPandaIDE/widgets/choosethemedialog.cpp | 22 ++++++++++++++++++++++ RedPandaIDE/widgets/choosethemedialog.ui | 4 ++-- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index f2cf7d1af..b4cec4f76 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,8 @@ Red Panda C++ Version 3.3 - enhancement: Auto indent contents in parenthesis. - fix: Use "/" instead of "\" in the path of compile target. - - fix: crash when debug. + - fix: Qt 6 version crashed when debug. + - enhancement: Auto scale the main ui & choose theme dialog at the first run. Red Panda C++ Version 3.2 diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index aa19f2d81..4bc25acf3 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1134,6 +1134,17 @@ void MainWindow::applyUISettings() ui->tabMessages->setShrinkedFlag(true); if (settings.shrinkExplorerTabs()) ui->tabExplorer->setShrinkedFlag(true); +#if defined(Q_OS_WIN) && QT_VERSION_MAJOR == 5 + if (settings.mainWindowGeometry().isEmpty()) { + //first run, adjust size with dpi + int w = width()*screenDPI()/96; + int h = height()*screenDPI()/96; + resize(w,h); + ui->tabMessages->setBeforeShrinkSize(settings.messagesTabsSize()*screenDPI()/96); + ui->tabExplorer->setBeforeShrinkSize(settings.explorerTabsSize()*screenDPI()/96); + } + +#endif } QFileSystemWatcher *MainWindow::fileSystemWatcher() diff --git a/RedPandaIDE/widgets/choosethemedialog.cpp b/RedPandaIDE/widgets/choosethemedialog.cpp index 8d50eb57e..77a587738 100644 --- a/RedPandaIDE/widgets/choosethemedialog.cpp +++ b/RedPandaIDE/widgets/choosethemedialog.cpp @@ -17,11 +17,33 @@ #include "choosethemedialog.h" #include "ui_choosethemedialog.h" +#include +#include + ChooseThemeDialog::ChooseThemeDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ChooseThemeDialog) { ui->setupUi(this); +#if defined(Q_OS_WIN) && QT_VERSION_MAJOR == 5 + //first run, adjust size with dpi + int dpi = qApp->primaryScreen()->logicalDotsPerInch(); +// int w = width()*dpi/96; +// int h = height()*dpi/96; +// ui->lblDark + double dpr = 96.0 / qApp->primaryScreen()->logicalDotsPerInch(); + QPixmap p = ui->lblLight->pixmap(Qt::ReturnByValue); + p.setDevicePixelRatio(dpr); + ui->lblLight->setPixmap(p); + p = ui->lblDark->pixmap(Qt::ReturnByValue); + p.setDevicePixelRatio(dpr); + ui->lblDark->setPixmap(p); + QFontMetrics fm{font()}; + QFont f{font()}; + + f.setPixelSize(fm.height()*dpi/96); + setFont(f); +#endif #ifdef ENABLE_LUA_ADDON ui->rbAuto->setVisible(true); #else diff --git a/RedPandaIDE/widgets/choosethemedialog.ui b/RedPandaIDE/widgets/choosethemedialog.ui index 96b9360bb..24bd037d6 100644 --- a/RedPandaIDE/widgets/choosethemedialog.ui +++ b/RedPandaIDE/widgets/choosethemedialog.ui @@ -21,7 +21,7 @@ - + QFrame::Box @@ -37,7 +37,7 @@ - + QFrame::Box