Improve color-coding for user disambiguation
See also: https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal
This commit is contained in:
committed by
Carl Schwan
parent
e838f7423d
commit
d6e1a6a45b
@@ -5,9 +5,35 @@
|
|||||||
*/
|
*/
|
||||||
#include "neochatuser.h"
|
#include "neochatuser.h"
|
||||||
|
|
||||||
|
#include <PlatformTheme> // Kirigami
|
||||||
|
|
||||||
#include "csapi/profile.h"
|
#include "csapi/profile.h"
|
||||||
|
|
||||||
|
NeoChatUser::NeoChatUser(QString userId, Connection *connection)
|
||||||
|
: User(userId, connection)
|
||||||
|
{
|
||||||
|
m_theme = static_cast<Kirigami::PlatformTheme *>(qmlAttachedPropertiesObject<Kirigami::PlatformTheme>(this, true));
|
||||||
|
Q_ASSERT(m_theme);
|
||||||
|
|
||||||
|
connect(m_theme, &Kirigami::PlatformTheme::colorsChanged, this, &NeoChatUser::polishColor);
|
||||||
|
}
|
||||||
|
|
||||||
QColor NeoChatUser::color()
|
QColor NeoChatUser::color()
|
||||||
{
|
{
|
||||||
return QColor::fromHslF(hueF(), 0.7, 0.5, 1);
|
return m_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NeoChatUser::setColor(QColor color)
|
||||||
|
{
|
||||||
|
if (m_color == color)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_color = color;
|
||||||
|
emit colorChanged(m_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()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,17 +10,30 @@
|
|||||||
#include "room.h"
|
#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
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QColor color READ color CONSTANT)
|
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||||
public:
|
public:
|
||||||
NeoChatUser(QString userId, Connection *connection)
|
NeoChatUser(QString userId, Connection *connection);
|
||||||
: User(userId, connection)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
QColor color();
|
QColor color();
|
||||||
|
void setColor(QColor color);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void colorChanged(QColor color);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Kirigami::PlatformTheme *m_theme = nullptr;
|
||||||
|
QColor m_color;
|
||||||
|
|
||||||
|
void polishColor();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user