summary refs log tree commit diff
path: root/src/timeline/TimelineItem.cpp
diff options
context:
space:
mode:
authorredsky17 <joedonofry@gmail.com>2019-01-20 04:43:48 +0000
committerredsky17 <joedonofry@gmail.com>2019-01-20 04:43:48 +0000
commit237c7ad114b7c3d6960fdaf712b600e715eff082 (patch)
tree77f9f2f3f8eb6256a538e653bd1ed2b615fd8625 /src/timeline/TimelineItem.cpp
parentUpdate user id color generation (diff)
downloadnheko-237c7ad114b7c3d6960fdaf712b600e715eff082.tar.xz
Author Color Fixes
Author color is now cached so that it will not be re-calculated
each time a new message is posted.  This cache gets cleared when
the theme is changed.

Additionally, the author color is now automatically refreshed
when the theme is changed, fixing the issue where you had to
change rooms before the colors would switch.
Diffstat (limited to 'src/timeline/TimelineItem.cpp')
-rw-r--r--src/timeline/TimelineItem.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp

index bd3d73bc..103bd6d6 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp
@@ -192,7 +192,8 @@ TimelineItem::init() emit eventRedacted(event_id_); }); }); - + connect( + ChatPage::instance(), &ChatPage::themeChanged, this, &TimelineItem::refreshAuthorColor); connect(markAsRead_, &QAction::triggered, this, &TimelineItem::sendReadReceipt); connect(viewRawMessage_, &QAction::triggered, this, &TimelineItem::openRawMessageViewer); @@ -603,6 +604,21 @@ TimelineItem::generateBody(const QString &body) }); } +void +TimelineItem::refreshAuthorColor() +{ + if (userName_) { + QString userColor = utils::getAuthorColor(userName_->text()); + if (userColor.isEmpty()) { + qApp->style()->polish(this); + // generate user's unique color. + auto backCol = backgroundColor().name(); + userColor = utils::generateContrastingHexColor(userName_->text(), backCol); + utils::addAuthorColor(userName_->text(), userColor); + } + userName_->setStyleSheet("QLabel { color : " + userColor + "; }"); + } +} // The username/timestamp is displayed along with the message body. void TimelineItem::generateBody(const QString &user_id, const QString &displayname, const QString &body) @@ -639,10 +655,14 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam // TimelineItem isn't displayed. This forces the QSS to get // loaded. - qApp->style()->polish(this); - // generate user's unique color. - auto backCol = backgroundColor().name(); - auto userColor = utils::generateContrastingHexColor(user_id, backCol); + QString userColor = utils::getAuthorColor(user_id); + if (userColor.isEmpty()) { + qApp->style()->polish(this); + // generate user's unique color. + auto backCol = backgroundColor().name(); + userColor = utils::generateContrastingHexColor(user_id, backCol); + utils::addAuthorColor(user_id, userColor); + } userName_->setStyleSheet("QLabel { color : " + userColor + "; }"); auto filter = new UserProfileFilter(user_id, userName_);