diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index d70d9cd25..42d9d4340 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -304,10 +304,49 @@ bool NotebookTab::isSelected() const return this->selected_; } +void NotebookTab::updateHighlightSources( + const QHash &removedHighlightSources) +{ + for (const auto &[otherChannel, otherEvent] : + removedHighlightSources.asKeyValueRange()) + { + this->highlightSources_.remove(otherChannel); + } + + if (this->highlightSources_.empty()) + { + this->highlightState_ = HighlightState::None; + this->update(); + } +} + void NotebookTab::setSelected(bool value) { this->selected_ = value; + if (value == true) + { + 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->updateHighlightSources(this->highlightSources_); + } + } + } + } + } + + this->highlightSources_.clear(); + this->highlightState_ = HighlightState::None; this->update(); @@ -362,6 +401,7 @@ bool NotebookTab::isLive() const void NotebookTab::setHighlightState(HighlightState newHighlightStyle) { + // change this to "copy" highlight state, its used by duplicating a tab if (this->isSelected()) { return; @@ -392,6 +432,14 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle, return; } + if (!this->shouldMessageHighlight(channelViewSource, message)) + { + return; + } + + this->highlightSources_.insert(channelViewSource.underlyingChannel(), + HighlightEvent{}); + if (!this->highlightEnabled_ && newHighlightStyle == HighlightState::NewMessage) { @@ -404,6 +452,13 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle, return; } + this->highlightState_ = newHighlightStyle; + this->update(); +} + +bool NotebookTab::shouldMessageHighlight(const ChannelView &channelViewSource, + const MessagePtr &message) const +{ auto *visibleSplitContainer = dynamic_cast(this->notebook_->getSelectedPage()); if (visibleSplitContainer != nullptr) @@ -426,13 +481,12 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle, visibleSplit->getChannelView().shouldIncludeMessage(message) && isSubset(filterIdsSource, filterIdsSplit)) { - return; + return false; } } } - this->highlightState_ = newHighlightStyle; - this->update(); + return true; } HighlightState NotebookTab::highlightState() const diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index 7284a1786..c709eb42e 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -111,6 +111,15 @@ private: int normalTabWidthForHeight(int height) const; + bool shouldMessageHighlight(const ChannelView &channelViewSource, + const MessagePtr &message) const; + + struct HighlightEvent { + }; + + void updateHighlightSources( + const QHash &removedHighlightSources); + QPropertyAnimation positionChangedAnimation_; QPoint positionAnimationDesiredPoint_; @@ -139,6 +148,8 @@ private: QMenu menu_; + QHash highlightSources_; + pajlada::Signals::SignalHolder managedConnections_; };