diff options
author | redsky17 <joedonofry@gmail.com> | 2019-01-18 04:09:42 +0000 |
---|---|---|
committer | redsky17 <joedonofry@gmail.com> | 2019-01-18 04:09:42 +0000 |
commit | 1882198e4b1df455e3e125d4729790a9fd881809 (patch) | |
tree | 483bb1e82bb0e430203bc8034e1f212c672620e4 /src | |
parent | Merge branch 'master' of github.com:nheko-reborn/nheko (diff) | |
download | nheko-1882198e4b1df455e3e125d4729790a9fd881809.tar.xz |
Make the author text slightly large.
Add author color generated based on user id.
Diffstat (limited to 'src')
-rw-r--r-- | src/Utils.cpp | 17 | ||||
-rw-r--r-- | src/Utils.h | 4 | ||||
-rw-r--r-- | src/timeline/TimelineItem.cpp | 8 |
3 files changed, 27 insertions, 2 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp index 8176cb43..6229d42a 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -382,6 +382,23 @@ utils::linkColor() return QPalette().color(QPalette::Link).name(); } +QString +utils::generateHexColor(const QString &input) +{ + auto hash = 0; + + for (int i = 0; i < input.length(); i++) { + hash = input.at(i).digitValue() + ((hash << 5) - hash); + } + hash *= 13; + QString colour("#"); + for (int i = 0; i < 3; i++) { + int value = (hash >> (i * 8)) & 0xFF; + colour.append(("00" + QString::number(value, 16)).right(2)); + } + return colour; +} + void utils::centerWidget(QWidget *widget, QWidget *parent) { diff --git a/src/Utils.h b/src/Utils.h index 2a029943..3ce2d758 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -227,6 +227,10 @@ markdownToHtml(const QString &text); QString linkColor(); +//! Given an input string, create a color string +QString +generateHexColor(const QString &string); + //! Center a widget in relation to another widget. void centerWidget(QWidget *widget, QWidget *parent); diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index e962d468..3df78ff6 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -622,8 +622,10 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam sender = displayname.split(":")[0].split("@")[1]; } + auto userColor = utils::generateHexColor(user_id); + QFont usernameFont; - usernameFont.setPointSizeF(usernameFont.pointSizeF()); + usernameFont.setPointSizeF(usernameFont.pointSizeF() * 1.1); usernameFont.setWeight(QFont::Medium); QFontMetrics fm(usernameFont); @@ -637,6 +639,8 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam userName_->setAlignment(Qt::AlignLeft | Qt::AlignTop); userName_->setFixedWidth(QFontMetrics(userName_->font()).width(userName_->text())); + userName_->setStyleSheet("QLabel { color : " + userColor + "; }"); + auto filter = new UserProfileFilter(user_id, userName_); userName_->installEventFilter(filter); userName_->setCursor(Qt::PointingHandCursor); @@ -837,4 +841,4 @@ TimelineItem::openRawMessageViewer() const "failed to serialize event ({}, {})", room_id, event_id); } }); -} +} \ No newline at end of file |