user details dialog fixes
This commit is contained in:
24
src/utils.h
24
src/utils.h
@@ -3,9 +3,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
#include <QGuiApplication>
|
||||
#include <QPalette>
|
||||
#include <QQmlEngine>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <Quotient/user.h>
|
||||
|
||||
class QmlUtils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -26,11 +31,30 @@ public:
|
||||
}
|
||||
|
||||
Q_INVOKABLE bool isValidJson(const QByteArray &json);
|
||||
Q_INVOKABLE QString escapeString(const QString &string);
|
||||
Q_INVOKABLE QColor getUserColor(qreal hueF);
|
||||
|
||||
private:
|
||||
QmlUtils() = default;
|
||||
};
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Get a color for a user from a hueF value.
|
||||
*
|
||||
* The lightness of the color will be modified depending on the current palette in
|
||||
* order to maintain contrast.
|
||||
*/
|
||||
inline QColor getUserColor(qreal hueF)
|
||||
{
|
||||
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
|
||||
return QColor::fromHslF(hueF, 1, -0.7 * lightness + 0.9, 1);
|
||||
}
|
||||
}
|
||||
|
||||
namespace TextRegex
|
||||
{
|
||||
static const QRegularExpression endTagType{QStringLiteral("(>| )")};
|
||||
|
||||
Reference in New Issue
Block a user