initial state of selecting to unhiglight

This commit is contained in:
unknown 2024-10-17 13:16:37 +02:00
parent 7728f01916
commit edaafac010
2 changed files with 68 additions and 3 deletions

View file

@ -304,10 +304,49 @@ bool NotebookTab::isSelected() const
return this->selected_; return this->selected_;
} }
void NotebookTab::updateHighlightSources(
const QHash<ChannelPtr, HighlightEvent> &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) void NotebookTab::setSelected(bool value)
{ {
this->selected_ = value; this->selected_ = value;
if (value == true)
{
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
if (splitNotebook)
{
for (int i = 0; i < splitNotebook->getPageCount(); ++i)
{
auto *splitContainer =
dynamic_cast<SplitContainer *>(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->highlightState_ = HighlightState::None;
this->update(); this->update();
@ -362,6 +401,7 @@ bool NotebookTab::isLive() const
void NotebookTab::setHighlightState(HighlightState newHighlightStyle) void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
{ {
// change this to "copy" highlight state, its used by duplicating a tab
if (this->isSelected()) if (this->isSelected())
{ {
return; return;
@ -392,6 +432,14 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle,
return; return;
} }
if (!this->shouldMessageHighlight(channelViewSource, message))
{
return;
}
this->highlightSources_.insert(channelViewSource.underlyingChannel(),
HighlightEvent{});
if (!this->highlightEnabled_ && if (!this->highlightEnabled_ &&
newHighlightStyle == HighlightState::NewMessage) newHighlightStyle == HighlightState::NewMessage)
{ {
@ -404,6 +452,13 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle,
return; return;
} }
this->highlightState_ = newHighlightStyle;
this->update();
}
bool NotebookTab::shouldMessageHighlight(const ChannelView &channelViewSource,
const MessagePtr &message) const
{
auto *visibleSplitContainer = auto *visibleSplitContainer =
dynamic_cast<SplitContainer *>(this->notebook_->getSelectedPage()); dynamic_cast<SplitContainer *>(this->notebook_->getSelectedPage());
if (visibleSplitContainer != nullptr) if (visibleSplitContainer != nullptr)
@ -426,13 +481,12 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle,
visibleSplit->getChannelView().shouldIncludeMessage(message) && visibleSplit->getChannelView().shouldIncludeMessage(message) &&
isSubset(filterIdsSource, filterIdsSplit)) isSubset(filterIdsSource, filterIdsSplit))
{ {
return; return false;
} }
} }
} }
this->highlightState_ = newHighlightStyle; return true;
this->update();
} }
HighlightState NotebookTab::highlightState() const HighlightState NotebookTab::highlightState() const

View file

@ -111,6 +111,15 @@ private:
int normalTabWidthForHeight(int height) const; int normalTabWidthForHeight(int height) const;
bool shouldMessageHighlight(const ChannelView &channelViewSource,
const MessagePtr &message) const;
struct HighlightEvent {
};
void updateHighlightSources(
const QHash<ChannelPtr, HighlightEvent> &removedHighlightSources);
QPropertyAnimation positionChangedAnimation_; QPropertyAnimation positionChangedAnimation_;
QPoint positionAnimationDesiredPoint_; QPoint positionAnimationDesiredPoint_;
@ -139,6 +148,8 @@ private:
QMenu menu_; QMenu menu_;
QHash<ChannelPtr, HighlightEvent> highlightSources_;
pajlada::Signals::SignalHolder managedConnections_; pajlada::Signals::SignalHolder managedConnections_;
}; };