From 66bcc2105aee6631c765b441cb9030e86b4142b7 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Tue, 2 Feb 2021 22:40:32 +0100 Subject: [PATCH] Only keep one Kirigami theme instance for all users Fetching the Kirigami Theme via attached properties is expensive. The theme is also going to be the same for all users so it's enough to only do it once. --- src/neochatuser.cpp | 13 +++++++++---- src/neochatuser.h | 1 - 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/neochatuser.cpp b/src/neochatuser.cpp index afed0fa43..690b5eb01 100644 --- a/src/neochatuser.cpp +++ b/src/neochatuser.cpp @@ -10,13 +10,18 @@ #include "csapi/profile.h" +static Kirigami::PlatformTheme * s_theme = nullptr; + NeoChatUser::NeoChatUser(QString userId, Connection *connection) : User(std::move(userId), connection) { - m_theme = static_cast(qmlAttachedPropertiesObject(this, true)); - Q_ASSERT(m_theme); + if (!s_theme) { + s_theme = static_cast(qmlAttachedPropertiesObject(this, true)); + Q_ASSERT(s_theme); + } - connect(m_theme, &Kirigami::PlatformTheme::colorsChanged, this, &NeoChatUser::polishColor); + connect(s_theme, &Kirigami::PlatformTheme::colorsChanged, this, &NeoChatUser::polishColor); + polishColor(); } QColor NeoChatUser::color() @@ -37,5 +42,5 @@ void NeoChatUser::setColor(const QColor &color) void NeoChatUser::polishColor() { // https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal - setColor(QColor::fromHslF(hueF(), 1 - m_theme->alternateBackgroundColor().saturationF(), -0.7 * m_theme->alternateBackgroundColor().lightnessF() + 0.9, m_theme->textColor().alphaF())); + setColor(QColor::fromHslF(hueF(), 1 - s_theme->alternateBackgroundColor().saturationF(), -0.7 * s_theme->alternateBackgroundColor().lightnessF() + 0.9, s_theme->textColor().alphaF())); } diff --git a/src/neochatuser.h b/src/neochatuser.h index a1a269074..d203abab8 100644 --- a/src/neochatuser.h +++ b/src/neochatuser.h @@ -32,7 +32,6 @@ Q_SIGNALS: void colorChanged(QColor _t1); private: - Kirigami::PlatformTheme *m_theme = nullptr; QColor m_color; void polishColor();