- enhancement: correct handle windows dpi change event

This commit is contained in:
Roy Qu 2022-01-26 21:36:31 +08:00
parent 5a82da83fb
commit 99a47db9bc
7 changed files with 32 additions and 19 deletions

View File

@ -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

View File

@ -27,6 +27,7 @@
#include <QAbstractNativeEventFilter>
#include <QDesktopWidget>
#include <QDir>
#include <QScreen>
#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) {

View File

@ -51,6 +51,7 @@
#include <QLineEdit>
#include <QMessageBox>
#include <QMimeData>
#include <QScreen>
#include <QTcpSocket>
#include <QTemporaryFile>
#include <QTextBlock>
@ -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()<<screen()<<screen()->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()<<pointToPixel(pSettings->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<QWidget*>()) {
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()) {

View File

@ -685,6 +685,7 @@ protected:
void closeEvent(QCloseEvent *event) override;
void showEvent(QShowEvent* event) override;
void hideEvent(QHideEvent *event) override;
};
extern MainWindow* pMainWindow;

View File

@ -30,7 +30,8 @@
#include <QStyleFactory>
#include <QDateTime>
#include <QColor>
#include <QDesktopWidget>
#include <QWindow>
#include <QScreen>
#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;
}

View File

@ -231,9 +231,8 @@ bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QSt
class CppParser;
void resetCppParser(std::shared_ptr<CppParser> parser, int compilerSetIndex=-1);
float desktopDpi();
void setDesktopDpi(float dpi);
int screenDPI();
void setScreenDPI(int dpi);
float pointToPixel(float point);
float pixelToPoint(float pixel);

View File

@ -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) {