mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Compare commits
1 commit
fec11f2d78
...
df9401f6a1
Author | SHA1 | Date | |
---|---|---|---|
df9401f6a1 |
|
@ -305,25 +305,37 @@ bool NotebookTab::isSelected() const
|
||||||
return this->selected_;
|
return this->selected_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotebookTab::removeNewMessageSource(
|
||||||
|
const ChannelView::ChannelViewID &source)
|
||||||
|
{
|
||||||
|
this->highlightSources_.newMessageSource.erase(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotebookTab::removeHighlightedSource(
|
||||||
|
const ChannelView::ChannelViewID &source)
|
||||||
|
{
|
||||||
|
this->highlightSources_.highlightedSource.erase(source);
|
||||||
|
}
|
||||||
|
|
||||||
void NotebookTab::removeHighlightStateChangeSources(
|
void NotebookTab::removeHighlightStateChangeSources(
|
||||||
const HighlightSources &toRemove)
|
const HighlightSources &toRemove)
|
||||||
{
|
{
|
||||||
for (const auto &[source, _] : toRemove)
|
for (const auto &source : toRemove.newMessageSource)
|
||||||
{
|
{
|
||||||
this->removeHighlightSource(source);
|
this->removeNewMessageSource(source);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotebookTab::removeHighlightSource(
|
for (const auto &source : toRemove.highlightedSource)
|
||||||
const ChannelView::ChannelViewID &source)
|
|
||||||
{
|
{
|
||||||
this->highlightSources_.erase(source);
|
this->removeHighlightedSource(source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
|
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
|
||||||
{
|
{
|
||||||
auto channelViewId = channelViewSource.getID();
|
auto channelViewId = channelViewSource.getID();
|
||||||
this->removeHighlightSource(channelViewId);
|
this->removeHighlightedSource(channelViewId);
|
||||||
|
this->removeNewMessageSource(channelViewId);
|
||||||
this->updateHighlightStateDueSourcesChange();
|
this->updateHighlightStateDueSourcesChange();
|
||||||
|
|
||||||
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
|
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
|
||||||
|
@ -338,7 +350,8 @@ void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
|
||||||
auto *tab = splitContainer->getTab();
|
auto *tab = splitContainer->getTab();
|
||||||
if (tab && tab != this)
|
if (tab && tab != this)
|
||||||
{
|
{
|
||||||
tab->removeHighlightSource(channelViewId);
|
tab->removeHighlightedSource(channelViewId);
|
||||||
|
tab->removeNewMessageSource(channelViewId);
|
||||||
tab->updateHighlightStateDueSourcesChange();
|
tab->updateHighlightStateDueSourcesChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -348,17 +361,13 @@ void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
|
||||||
|
|
||||||
void NotebookTab::updateHighlightStateDueSourcesChange()
|
void NotebookTab::updateHighlightStateDueSourcesChange()
|
||||||
{
|
{
|
||||||
if (std::ranges::any_of(this->highlightSources_, [](const auto &keyval) {
|
if (!this->highlightSources_.highlightedSource.empty())
|
||||||
return keyval.second == HighlightState::Highlighted;
|
|
||||||
}))
|
|
||||||
{
|
{
|
||||||
assert(this->highlightState_ == HighlightState::Highlighted);
|
assert(this->highlightState_ == HighlightState::Highlighted);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::ranges::any_of(this->highlightSources_, [](const auto &keyval) {
|
if (!this->highlightSources_.newMessageSource.empty())
|
||||||
return keyval.second == HighlightState::NewMessage;
|
|
||||||
}))
|
|
||||||
{
|
{
|
||||||
if (this->highlightState_ != HighlightState::NewMessage)
|
if (this->highlightState_ != HighlightState::NewMessage)
|
||||||
{
|
{
|
||||||
|
@ -382,7 +391,8 @@ void NotebookTab::copyHighlightStateAndSourcesFrom(const NotebookTab *sourceTab)
|
||||||
{
|
{
|
||||||
if (this->isSelected())
|
if (this->isSelected())
|
||||||
{
|
{
|
||||||
assert(this->highlightSources_.empty());
|
assert(this->highlightSources_.highlightedSource.empty());
|
||||||
|
assert(this->highlightSources_.newMessageSource.empty());
|
||||||
assert(this->highlightState_ == HighlightState::None);
|
assert(this->highlightState_ == HighlightState::None);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -494,7 +504,8 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
|
||||||
{
|
{
|
||||||
if (this->isSelected())
|
if (this->isSelected())
|
||||||
{
|
{
|
||||||
assert(this->highlightSources_.empty());
|
assert(this->highlightSources_.highlightedSource.empty());
|
||||||
|
assert(this->highlightSources_.newMessageSource.empty());
|
||||||
assert(this->highlightState_ == HighlightState::None);
|
assert(this->highlightState_ == HighlightState::None);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -523,7 +534,8 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
|
||||||
{
|
{
|
||||||
if (this->isSelected())
|
if (this->isSelected())
|
||||||
{
|
{
|
||||||
assert(this->highlightSources_.empty());
|
assert(this->highlightSources_.highlightedSource.empty());
|
||||||
|
assert(this->highlightSources_.newMessageSource.empty());
|
||||||
assert(this->highlightState_ == HighlightState::None);
|
assert(this->highlightState_ == HighlightState::None);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -545,16 +557,19 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
|
||||||
|
|
||||||
switch (newHighlightStyle)
|
switch (newHighlightStyle)
|
||||||
{
|
{
|
||||||
case HighlightState::Highlighted:
|
case HighlightState::Highlighted: {
|
||||||
// override lower states
|
if (!this->highlightSources_.highlightedSource.contains(
|
||||||
this->highlightSources_.insert_or_assign(channelViewId,
|
channelViewId))
|
||||||
newHighlightStyle);
|
|
||||||
case HighlightState::NewMessage: {
|
|
||||||
// only insert if no state already there to avoid overriding
|
|
||||||
if (!this->highlightSources_.contains(channelViewId))
|
|
||||||
{
|
{
|
||||||
this->highlightSources_.emplace(channelViewId,
|
this->highlightSources_.highlightedSource.insert(channelViewId);
|
||||||
newHighlightStyle);
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case HighlightState::NewMessage: {
|
||||||
|
if (!this->highlightSources_.newMessageSource.contains(
|
||||||
|
channelViewId))
|
||||||
|
{
|
||||||
|
this->highlightSources_.newMessageSource.insert(channelViewId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,12 +125,25 @@ private:
|
||||||
bool shouldMessageHighlight(const ChannelView &channelViewSource,
|
bool shouldMessageHighlight(const ChannelView &channelViewSource,
|
||||||
const MessagePtr &message) const;
|
const MessagePtr &message) const;
|
||||||
|
|
||||||
using HighlightSources =
|
struct HighlightSources {
|
||||||
std::unordered_map<ChannelView::ChannelViewID, HighlightState>;
|
// Source of the update to the highlight status is the split
|
||||||
HighlightSources highlightSources_;
|
// in which a message that causes the update appears.
|
||||||
|
// This message can be just a plain message causing the
|
||||||
|
// HighlightState::NewMessage state, or a message that pings the user
|
||||||
|
// causing the HighlightState::Highlighted state
|
||||||
|
std::unordered_set<ChannelView::ChannelViewID> newMessageSource;
|
||||||
|
std::unordered_set<ChannelView::ChannelViewID> highlightedSource;
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
this->newMessageSource.clear();
|
||||||
|
this->highlightedSource.clear();
|
||||||
|
}
|
||||||
|
} highlightSources_;
|
||||||
|
|
||||||
void removeHighlightStateChangeSources(const HighlightSources &toRemove);
|
void removeHighlightStateChangeSources(const HighlightSources &toRemove);
|
||||||
void removeHighlightSource(const ChannelView::ChannelViewID &source);
|
void removeNewMessageSource(const ChannelView::ChannelViewID &source);
|
||||||
|
void removeHighlightedSource(const ChannelView::ChannelViewID &source);
|
||||||
void updateHighlightStateDueSourcesChange();
|
void updateHighlightStateDueSourcesChange();
|
||||||
|
|
||||||
QPropertyAnimation positionChangedAnimation_;
|
QPropertyAnimation positionChangedAnimation_;
|
||||||
|
|
Loading…
Reference in a new issue