diff --git a/src/widgets/Notebook.cpp b/src/widgets/Notebook.cpp index 2a01020fc..53c6dfcfa 100644 --- a/src/widgets/Notebook.cpp +++ b/src/widgets/Notebook.cpp @@ -204,7 +204,7 @@ void Notebook::duplicatePage(QWidget *page) { newTabPosition = tabPosition + 1; } - auto newTabHighlightState = item->tab->highlightState(); + QString newTabTitle = ""; if (item->tab->hasCustomTitle()) { @@ -213,7 +213,7 @@ void Notebook::duplicatePage(QWidget *page) auto *tab = this->addPageAt(newContainer, newTabPosition, newTabTitle, false); - tab->setHighlightState(newTabHighlightState); + tab->copyHighlightStateAndSourcesFrom(item->tab); newContainer->setTab(tab); } diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index ebfdd2ff8..66bc0cc4a 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -304,15 +304,14 @@ bool NotebookTab::isSelected() const return this->selected_; } -void NotebookTab::updateHighlightSources( - const HighlightSources &removedHighlightSources) +void NotebookTab::removeHighlightSources(const HighlightSources &toRemove) { - for (const auto &source : removedHighlightSources.newMessageSource) + for (const auto &source : toRemove.newMessageSource) { this->highlightSources_.newMessageSource.erase(source); } - for (const auto &source : removedHighlightSources.highlightedSource) + for (const auto &source : toRemove.highlightedSource) { this->highlightSources_.highlightedSource.erase(source); } @@ -341,6 +340,31 @@ void NotebookTab::updateHighlightSources( } } +void NotebookTab::copyHighlightStateAndSourcesFrom(const NotebookTab *sourceTab) +{ + if (this->isSelected()) + { + return; + } + + this->highlightSources_ = sourceTab->highlightSources_; + + if (!this->highlightEnabled_ && + sourceTab->highlightState_ == HighlightState::NewMessage) + { + return; + } + + if (this->highlightState_ == sourceTab->highlightState_ || + this->highlightState_ == HighlightState::Highlighted) + { + return; + } + + this->highlightState_ = sourceTab->highlightState_; + this->update(); +} + void NotebookTab::setSelected(bool value) { this->selected_ = value; @@ -359,7 +383,7 @@ void NotebookTab::setSelected(bool value) auto *tab = splitContainer->getTab(); if (tab && tab != this) { - tab->updateHighlightSources(this->highlightSources_); + tab->removeHighlightSources(this->highlightSources_); } } } @@ -420,30 +444,6 @@ bool NotebookTab::isLive() const return this->isLive_; } -void NotebookTab::setHighlightState(HighlightState newHighlightStyle) -{ - // change this to "copy" highlight state, its used by duplicating a tab - if (this->isSelected()) - { - return; - } - - if (!this->highlightEnabled_ && - newHighlightStyle == HighlightState::NewMessage) - { - return; - } - - if (this->highlightState_ == newHighlightStyle || - this->highlightState_ == HighlightState::Highlighted) - { - return; - } - - this->highlightState_ = newHighlightStyle; - this->update(); -} - void NotebookTab::setHighlightState(HighlightState newHighlightStyle, const ChannelView &channelViewSource, const MessagePtr &message) @@ -533,11 +533,6 @@ bool NotebookTab::shouldMessageHighlight(const ChannelView &channelViewSource, return true; } -HighlightState NotebookTab::highlightState() const -{ - return this->highlightState_; -} - void NotebookTab::setHighlightsEnabled(const bool &newVal) { this->highlightNewMessagesAction_->setChecked(newVal); diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index e5fe6c9cd..ba073ad2d 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -60,12 +60,10 @@ public: **/ bool isLive() const; - void setHighlightState(HighlightState style); void setHighlightState(HighlightState style, const ChannelView &channelViewSource, const MessagePtr &message); - HighlightState highlightState() const; - + void copyHighlightStateAndSourcesFrom(const NotebookTab *sourceTab); void setHighlightsEnabled(const bool &newVal); bool hasHighlightsEnabled() const; @@ -126,8 +124,7 @@ private: } highlightSources_; - void updateHighlightSources( - const HighlightSources &removedHighlightSources); + void removeHighlightSources(const HighlightSources &toRemove); QPropertyAnimation positionChangedAnimation_; QPoint positionAnimationDesiredPoint_;