Don't segfault on shutdown
Use the current QPalette for user color instead of getting the platform theme from QML, which caused segfaults.
This commit is contained in:
@@ -3,24 +3,13 @@
|
|||||||
|
|
||||||
#include "neochatuser.h"
|
#include "neochatuser.h"
|
||||||
|
|
||||||
#include <PlatformTheme> // Kirigami
|
#include <QGuiApplication>
|
||||||
#include <utility>
|
#include <QPalette>
|
||||||
|
|
||||||
#include "csapi/profile.h"
|
|
||||||
|
|
||||||
#include "controller.h"
|
|
||||||
|
|
||||||
static Kirigami::PlatformTheme *s_theme = nullptr;
|
|
||||||
|
|
||||||
NeoChatUser::NeoChatUser(QString userId, Connection *connection)
|
NeoChatUser::NeoChatUser(QString userId, Connection *connection)
|
||||||
: User(std::move(userId), connection)
|
: User(std::move(userId), connection)
|
||||||
{
|
{
|
||||||
if (!s_theme) {
|
connect(static_cast<QGuiApplication *>(QGuiApplication::instance()), &QGuiApplication::paletteChanged, this, &NeoChatUser::polishColor);
|
||||||
s_theme = static_cast<Kirigami::PlatformTheme *>(qmlAttachedPropertiesObject<Kirigami::PlatformTheme>(&Controller::instance(), true));
|
|
||||||
Q_ASSERT(s_theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(s_theme, &Kirigami::PlatformTheme::colorsChanged, this, &NeoChatUser::polishColor);
|
|
||||||
polishColor();
|
polishColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,9 +30,7 @@ void NeoChatUser::setColor(const QColor &color)
|
|||||||
|
|
||||||
void NeoChatUser::polishColor()
|
void NeoChatUser::polishColor()
|
||||||
{
|
{
|
||||||
|
const auto lightness = static_cast<QGuiApplication *>(QGuiApplication::instance())->palette().color(QPalette::Active, QPalette::Window).lightnessF();
|
||||||
// https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal
|
// https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal
|
||||||
setColor(QColor::fromHslF(hueF(),
|
setColor(QColor::fromHslF(hueF(), 1, -0.7 * lightness + 0.9, 1));
|
||||||
1 - s_theme->alternateBackgroundColor().saturationF(),
|
|
||||||
-0.7 * s_theme->alternateBackgroundColor().lightnessF() + 0.9,
|
|
||||||
s_theme->textColor().alphaF()));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "room.h"
|
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
|
||||||
namespace Kirigami
|
|
||||||
{
|
|
||||||
class PlatformTheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
|
|
||||||
class NeoChatUser : public User
|
class NeoChatUser : public User
|
||||||
|
|||||||
Reference in New Issue
Block a user