Commit adf5b6e0 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Avoid needlessly reading font settings

Currently we call syncFonts every time a platformtheme is created and updated, which is way too often.

It is all global data, i.e. not specific to the concrete platformtheme instance, so move it to the style singleton.

Also only read the settings for smallFont when fonts were actually changed.

(cherry picked from commit 8c9435f0)
parent e2d6f088
Pipeline #134445 passed with stage
in 52 seconds
......@@ -55,6 +55,7 @@ public:
#endif
connect(qGuiApp, &QGuiApplication::fontDatabaseChanged, this, &StyleSingleton::notifyWatchersConfigurationChange);
connect(qGuiApp, &QGuiApplication::fontChanged, this, &StyleSingleton::notifyWatchersConfigurationChange);
/* QtTextRendering uses less memory, so use it in low power mode.
*
......@@ -83,6 +84,26 @@ public:
}
QQuickWindow::setTextRenderType(defaultTextRenderType);
smallFont = loadSmallFont();
}
QFont loadSmallFont() const
{
KSharedConfigPtr ptr = KSharedConfig::openConfig();
KConfigGroup general(ptr->group("general"));
return general.readEntry("smallestReadableFont", []() {
auto smallFont = qApp->font();
#ifndef Q_OS_WIN
if (smallFont.pixelSize() != -1) {
smallFont.setPixelSize(smallFont.pixelSize() - 2);
} else {
smallFont.setPointSize(smallFont.pointSize() - 2);
}
#endif
return smallFont;
}());
}
void refresh()
......@@ -177,12 +198,15 @@ public:
Q_SLOT void notifyWatchersConfigurationChange()
{
smallFont = loadSmallFont();
for (auto watcher : qAsConst(watchers)) {
watcher->syncFont();
watcher->setSmallFont(smallFont);
watcher->setDefaultFont(qApp->font());
}
}
KColorScheme buttonScheme;
QFont smallFont;
QVector<PlasmaDesktopTheme *> watchers;
......@@ -210,7 +234,9 @@ PlasmaDesktopTheme::PlasmaDesktopTheme(QObject *parent)
(*s_style)->watchers.append(this);
syncFont();
setDefaultFont(qGuiApp->font());
setSmallFont((*s_style)->smallFont);
syncWindow();
syncColors();
}
......@@ -248,23 +274,6 @@ void PlasmaDesktopTheme::syncWindow()
}
}
void PlasmaDesktopTheme::syncFont()
{
KSharedConfigPtr ptr = KSharedConfig::openConfig();
KConfigGroup general(ptr->group("general"));
setSmallFont(general.readEntry("smallestReadableFont", []() {
auto smallFont = qApp->font();
if (smallFont.pixelSize() != -1) {
smallFont.setPixelSize(smallFont.pixelSize() - 2);
} else {
smallFont.setPointSize(smallFont.pointSize() - 2);
}
return smallFont;
}()));
setDefaultFont(qGuiApp->font());
}
QIcon PlasmaDesktopTheme::iconFromTheme(const QString &name, const QColor &customColor)
{
#ifndef Q_OS_ANDROID
......@@ -366,7 +375,6 @@ void PlasmaDesktopTheme::syncColors()
bool PlasmaDesktopTheme::event(QEvent *event)
{
if (event->type() == Kirigami::PlatformThemeEvents::DataChangedEvent::type) {
syncFont();
syncColors();
}
......
......@@ -48,9 +48,6 @@ public:
protected:
bool event(QEvent *event) override;
protected Q_SLOTS:
void syncFont();
private:
friend class StyleSingleton;
QPointer<QWindow> m_window;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment