From 6416bf39275b4da522d9af622753ed697c5daad4 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sat, 3 Nov 2018 21:40:48 +0100 Subject: [PATCH] alternate color for historic messages --- src/widgets/helper/ChannelView.cpp | 31 +++++++++++++++++------------- src/widgets/helper/ChannelView.hpp | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 1b36631d9..149d28c90 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -620,26 +620,31 @@ void ChannelView::messageAddedAtStart(std::vector &messages) { std::vector messageRefs; messageRefs.resize(messages.size()); + + /// Create message layouts for (size_t i = 0; i < messages.size(); i++) { - messageRefs.at(i) = MessageLayoutPtr(new MessageLayout(messages.at(i))); + auto layout = new MessageLayout(messages.at(i)); + + // alternate color + if (!this->lastMessageHasAlternateBackgroundReverse_) + layout->flags.set(MessageLayoutFlag::AlternateBackground); + this->lastMessageHasAlternateBackgroundReverse_ = + !this->lastMessageHasAlternateBackgroundReverse_; + + messageRefs.at(i) = MessageLayoutPtr(layout); } - // if (!this->isPaused()) + /// Add the messages at the start + if (this->messages.pushFront(messageRefs).size() > 0) { - if (this->messages.pushFront(messageRefs).size() > 0) - { - if (this->scrollBar_->isAtBottom()) - { - this->scrollBar_->scrollToBottom(); - } - else - { - this->scrollBar_->offset(qreal(messages.size())); - } - } + if (this->scrollBar_->isAtBottom()) + this->scrollBar_->scrollToBottom(); + else + this->scrollBar_->offset(qreal(messages.size())); } + /// Add highlights std::vector highlights; highlights.reserve(messages.size()); for (size_t i = 0; i < messages.size(); i++) diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 5480e5f34..34b554336 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -149,6 +149,7 @@ private: bool updateQueued_ = false; bool messageWasAdded_ = false; bool lastMessageHasAlternateBackground_ = false; + bool lastMessageHasAlternateBackgroundReverse_ = true; QTimer pauseTimer_; std::unordered_map>