From 2884c828b03c940d26e776f803824cd3d499e416 Mon Sep 17 00:00:00 2001 From: unknown <1310440+hemirt@users.noreply.github.com> Date: Fri, 18 Oct 2024 09:24:34 +0200 Subject: [PATCH] update highlights of other tabs when adding new channel or changing channel --- src/widgets/helper/NotebookTab.cpp | 51 ++++++++++++++++++++++++--- src/widgets/helper/NotebookTab.hpp | 6 +++- src/widgets/splits/SplitContainer.cpp | 28 ++++++++++----- 3 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 5a6660639..a04725909 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -304,18 +304,59 @@ bool NotebookTab::isSelected() const return this->selected_; } -void NotebookTab::removeHighlightSources(const HighlightSources &toRemove) +void NotebookTab::removeNewMessageSource(const ChannelPtr &source) +{ + this->highlightSources_.newMessageSource.erase(source); +} + +void NotebookTab::removeHighlightedSource(const ChannelPtr &source) +{ + this->highlightSources_.highlightedSource.erase(source); +} + +void NotebookTab::removeHighlightStateChangeSources( + const HighlightSources &toRemove) { for (const auto &source : toRemove.newMessageSource) { - this->highlightSources_.newMessageSource.erase(source); + this->removeNewMessageSource(source); } for (const auto &source : toRemove.highlightedSource) { - this->highlightSources_.highlightedSource.erase(source); + this->removeHighlightedSource(source); } +} +void NotebookTab::newHighlightSourceAdded(const ChannelPtr &source) +{ + this->removeHighlightedSource(source); + this->removeNewMessageSource(source); + this->updateHighlightStateDueSourcesChange(); + + auto *splitNotebook = dynamic_cast(this->notebook_); + if (splitNotebook) + { + for (int i = 0; i < splitNotebook->getPageCount(); ++i) + { + auto *splitContainer = + dynamic_cast(splitNotebook->getPageAt(i)); + if (splitContainer) + { + auto *tab = splitContainer->getTab(); + if (tab && tab != this) + { + tab->removeHighlightedSource(source); + tab->removeNewMessageSource(source); + tab->updateHighlightStateDueSourcesChange(); + } + } + } + } +} + +void NotebookTab::updateHighlightStateDueSourcesChange() +{ if (!this->highlightSources_.highlightedSource.empty()) { assert(this->highlightState_ == HighlightState::Highlighted); @@ -388,7 +429,9 @@ void NotebookTab::setSelected(bool value) auto *tab = splitContainer->getTab(); if (tab && tab != this) { - tab->removeHighlightSources(this->highlightSources_); + tab->removeHighlightStateChangeSources( + this->highlightSources_); + tab->updateHighlightStateDueSourcesChange(); } } } diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index 8be7f1e97..cfd2e1d34 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -76,6 +76,7 @@ public: const MessagePtr &message); void copyHighlightStateAndSourcesFrom(const NotebookTab *sourceTab); void setHighlightsEnabled(const bool &newVal); + void newHighlightSourceAdded(const ChannelPtr &source); bool hasHighlightsEnabled() const; HighlightState highlightState() const; @@ -136,7 +137,10 @@ private: } highlightSources_; - void removeHighlightSources(const HighlightSources &toRemove); + void removeHighlightStateChangeSources(const HighlightSources &toRemove); + void removeNewMessageSource(const ChannelPtr &source); + void removeHighlightedSource(const ChannelPtr &source); + void updateHighlightStateDueSourcesChange(); QPropertyAnimation positionChangedAnimation_; QPoint positionAnimationDesiredPoint_; diff --git a/src/widgets/splits/SplitContainer.cpp b/src/widgets/splits/SplitContainer.cpp index 7b4192ca6..4e430c6b0 100644 --- a/src/widgets/splits/SplitContainer.cpp +++ b/src/widgets/splits/SplitContainer.cpp @@ -213,15 +213,25 @@ void SplitContainer::addSplit(Split *split) auto &&conns = this->connectionsPerSplit_[split]; - conns.managedConnect(split->getChannelView().tabHighlightRequested, - [this, &channelView = split->getChannelView()]( - HighlightState state, const MessagePtr &message) { - if (this->tab_ != nullptr) - { - this->tab_->updateHighlightState( - state, channelView, message); - } - }); + conns.managedConnect( + split->getChannelView().tabHighlightRequested, + [this, split](HighlightState state, const MessagePtr &message) { + if (this->tab_ != nullptr) + { + this->tab_->updateHighlightState(state, split->getChannelView(), + message); + } + }); + + conns.managedConnect(split->channelChanged, [this, split] { + qDebug() << "Changing Channel" + << split->getChannelView().underlyingChannel()->getName(); + if (this->tab_ != nullptr) + { + this->tab_->newHighlightSourceAdded( + split->getChannelView().underlyingChannel()); + } + }); conns.managedConnect(split->getChannelView().liveStatusChanged, [this]() { this->refreshTabLiveStatus();