Skip to content

Commit db52d9f

Browse files
committed
Fix font
1 parent 0a61310 commit db52d9f

File tree

5 files changed

+62
-26
lines changed

5 files changed

+62
-26
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DiffScope
22

3-
DiffSinger Editor developed by OpenVPI.
3+
Cross-platform SVS editor powered by DiffSinger.
44

55
## Supported Platforms
66

src/app/main.cpp

+37-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#include <QApplication>
2-
#include <QDebug>
3-
#include <QProcess>
4-
#include <QNetworkProxyFactory>
1+
#include <QtCore/QDebug>
2+
#include <QtCore/QProcess>
3+
#include <QtNetwork/QNetworkProxyFactory>
4+
#include <QtWidgets/QApplication>
5+
#include <QtWidgets/QToolTip>
56

67
#include <extensionsystem/pluginmanager.h>
78

@@ -73,29 +74,48 @@ class MyLoaderConfiguration : public Loader::LoaderConfiguration {
7374
}
7475

7576
value = settings->value(QStringLiteral("Font"));
76-
if (!value.isNull()) {
77-
QFont font;
78-
if (font.fromString(value.toString())) {
79-
QGuiApplication::setFont(font);
77+
{
78+
// Default font
79+
QFont font(QMAppExtension::systemDefaultFont());
80+
font.setPixelSize(12);
81+
82+
// Get font
83+
if (!value.isNull()) {
84+
font.fromString(value.toString());
8085
}
86+
87+
// Normalize font
8188
if (font.pixelSize() <= 0) {
8289
font.setPixelSize(12);
8390
}
8491
qIDec->setFontRatio(font.pixelSize() / 12.0);
92+
93+
// The application font is determined at startup and remains unchanged, using the
94+
// `userFont` property to record the changes made by the user during the current
95+
// application life.
96+
qApp->setProperty("userFont", font);
97+
qApp->setProperty("userFontInitial", font);
98+
99+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
100+
font.setPointSize(font.pixelSize() * 0.75 * qIDec->zoomRatio());
101+
#else
102+
font.setPixelSize(font.pixelSize() * qIDec->zoomRatio());
103+
#endif
104+
// Make the default font update with system dpi
105+
QGuiApplication::setFont(font);
106+
QToolTip::setFont(font);
85107
}
86-
// The application font is determined at startup and remains unchanged, using the
87-
// `userFont` property to record the changes made by the user during the current
88-
// application life.
89-
qApp->setProperty("userFont", QGuiApplication::font());
90108

91109
value = settings->value(QStringLiteral("UseSystemFont"));
92-
if (value.type() == QVariant::String) {
93-
qApp->setProperty("useSystemFont",
94-
value.toString().toLower() == QStringLiteral("true"));
95-
} else {
110+
{
111+
// Default value
96112
qApp->setProperty("useSystemFont", true);
113+
// Get value
114+
if (value.type() == QVariant::String) {
115+
qApp->setProperty("useSystemFont",
116+
value.toString().toLower() == QStringLiteral("true"));
117+
}
97118
}
98-
99119
settings->endGroup();
100120
}
101121

src/plugins/coreplugin/core/appextra.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace Core {
9090
QApplication::translate(
9191
"Application",
9292
"<h3>About Application</h3>"
93-
"<p>%1 is a cross-platform SVS editing application mainly powered by "
93+
"<p>%1 is a cross-platform SVS editing application powered by "
9494
"DiffSinger for virtual singer producers to make song compositions.</p>")
9595
.arg(appName);
9696

src/plugins/coreplugin/internal/settings/appearancepage.cpp

+22-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <QGroupBox>
1717
#include <QListView>
1818
#include <QCheckBox>
19+
#include <QToolTip>
1920

2021
#include <extensionsystem/pluginmanager.h>
2122

@@ -52,6 +53,24 @@ namespace Core::Internal {
5253
50, 75, 100, 125, 150, 175, 200, 225, 250,
5354
};
5455

56+
static inline QFont systemFont() {
57+
auto font = qAppExt->systemDefaultFont();
58+
font.setPixelSize(12);
59+
return font;
60+
}
61+
62+
static inline void syncAppFontSize() {
63+
auto font = qApp->property("userFontInitial").value<QFont>();
64+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
65+
font.setPointSize(font.pixelSize() * 0.75 * qIDec->zoomRatio());
66+
#else
67+
font.setPixelSize(font.pixelSize() * qIDec->zoomRatio());
68+
#endif
69+
// Make the default font update with system dpi
70+
QGuiApplication::setFont(font);
71+
QToolTip::setFont(font);
72+
}
73+
5574
class AppearancePageWidget : public QWidget {
5675
public:
5776
explicit AppearancePageWidget(QWidget *parent = nullptr) : QWidget(parent) {
@@ -135,12 +154,6 @@ namespace Core::Internal {
135154
QFont originalFont;
136155
bool originalUseSystemFont;
137156

138-
static QFont systemFont() {
139-
auto font = qAppExt->systemDefaultFont();
140-
font.setPixelSize(12);
141-
return font;
142-
}
143-
144157
private:
145158
void _q_useSystemFontButtonToggled(bool checked) {
146159
if (checked) {
@@ -160,6 +173,7 @@ namespace Core::Internal {
160173
void _q_zoomComboBoxIndexChanged(int index) {
161174
Q_UNUSED(this)
162175
qIDec->setZoomRatio(double(zoomRatioList[index]) / 100);
176+
syncAppFontSize();
163177
}
164178

165179
void updateFontText() const {
@@ -253,6 +267,8 @@ namespace Core::Internal {
253267
qApp->setProperty("userFont", m_widget->originalFont);
254268
qApp->setProperty("useSystemFont", m_widget->originalUseSystemFont);
255269

270+
syncAppFontSize();
271+
256272
// Save recorded arguments
257273
auto settings = ExtensionSystem::PluginManager::settings();
258274
settings->beginGroup("Preferences");

0 commit comments

Comments
 (0)