File indexing completed on 2024-04-14 15:03:12

0001 // SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
0002 // SPDX-License-Identifier: GPL-3.0-only
0003 
0004 #include "neochatuser.h"
0005 
0006 #include <QGuiApplication>
0007 #include <QJsonObject>
0008 #include <QPalette>
0009 
0010 #include <Quotient/connection.h>
0011 
0012 using namespace Quotient;
0013 
0014 NeoChatUser::NeoChatUser(QString userId, Connection *connection)
0015     : User(std::move(userId), connection)
0016 {
0017     connect(static_cast<QGuiApplication *>(QGuiApplication::instance()), &QGuiApplication::paletteChanged, this, &NeoChatUser::polishColor);
0018     polishColor();
0019 }
0020 
0021 QColor NeoChatUser::color()
0022 {
0023     return m_color;
0024 }
0025 
0026 void NeoChatUser::setColor(const QColor &color)
0027 {
0028     if (m_color == color) {
0029         return;
0030     }
0031 
0032     m_color = color;
0033     Q_EMIT colorChanged(m_color);
0034 }
0035 
0036 void NeoChatUser::polishColor()
0037 {
0038     const auto lightness = static_cast<QGuiApplication *>(QGuiApplication::instance())->palette().color(QPalette::Active, QPalette::Window).lightnessF();
0039     // https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal
0040     setColor(QColor::fromHslF(hueF(), 1, -0.7 * lightness + 0.9, 1));
0041 }
0042 
0043 #include "moc_neochatuser.cpp"