From 5f862c5e5ee6ec4b4c61c266dd74ad6591b0806d Mon Sep 17 00:00:00 2001 From: unknown <1310440+hemirt@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:56:14 +0200 Subject: [PATCH] solve highlighted tabs --- src/widgets/helper/NotebookTab.cpp | 62 ++++++++++++++++++++++++------ src/widgets/helper/NotebookTab.hpp | 18 ++++++--- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index febfbd305..ebfdd2ff8 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -305,18 +305,39 @@ bool NotebookTab::isSelected() const } void NotebookTab::updateHighlightSources( - const std::unordered_map - &removedHighlightSources) + const HighlightSources &removedHighlightSources) { - for (const auto &[otherChannel, otherEvent] : removedHighlightSources) + for (const auto &source : removedHighlightSources.newMessageSource) { - this->highlightSources_.erase(otherChannel); + this->highlightSources_.newMessageSource.erase(source); } - if (this->highlightSources_.empty()) + for (const auto &source : removedHighlightSources.highlightedSource) { - this->highlightState_ = HighlightState::None; - this->update(); + this->highlightSources_.highlightedSource.erase(source); + } + + if (!this->highlightSources_.highlightedSource.empty()) + { + // keep HighlightState::Highlighted + return; + } + + if (!this->highlightSources_.newMessageSource.empty()) + { + if (this->highlightState_ != HighlightState::NewMessage) + { + this->highlightState_ = HighlightState::NewMessage; + this->update(); + } + } + else + { + if (this->highlightState_ != HighlightState::None) + { + this->highlightState_ = HighlightState::None; + this->update(); + } } } @@ -437,11 +458,30 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle, return; } - if (!this->highlightSources_.contains( - channelViewSource.underlyingChannel())) + auto underlyingChannel = channelViewSource.underlyingChannel(); + + switch (newHighlightStyle) { - this->highlightSources_.emplace(channelViewSource.underlyingChannel(), - HighlightEvent{}); + case HighlightState::Highlighted: { + if (!this->highlightSources_.highlightedSource.contains( + underlyingChannel)) + { + this->highlightSources_.highlightedSource.insert( + underlyingChannel); + } + break; + } + case HighlightState::NewMessage: { + if (!this->highlightSources_.newMessageSource.contains( + underlyingChannel)) + { + this->highlightSources_.newMessageSource.insert( + underlyingChannel); + } + break; + } + case HighlightState::None: + break; } if (!this->highlightEnabled_ && diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index a7b1e518e..e5fe6c9cd 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -114,12 +114,20 @@ private: bool shouldMessageHighlight(const ChannelView &channelViewSource, const MessagePtr &message) const; - struct HighlightEvent { - }; + struct HighlightSources { + std::unordered_set newMessageSource; + std::unordered_set highlightedSource; + + void clear() + { + this->newMessageSource.clear(); + this->highlightedSource.clear(); + } + + } highlightSources_; void updateHighlightSources( - const std::unordered_map - &removedHighlightSources); + const HighlightSources &removedHighlightSources); QPropertyAnimation positionChangedAnimation_; QPoint positionAnimationDesiredPoint_; @@ -149,8 +157,6 @@ private: QMenu menu_; - std::unordered_map highlightSources_; - pajlada::Signals::SignalHolder managedConnections_; };