mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Compare commits
3 commits
e5e5a79645
...
1bdb118391
Author | SHA1 | Date | |
---|---|---|---|
|
1bdb118391 | ||
|
0e4897969b | ||
|
374e0c5fa0 |
5 changed files with 49 additions and 70 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "widgets/BaseWidget.hpp"
|
||||
|
||||
#include <ForwardDecl.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
#include <QList>
|
||||
|
|
|
@ -1063,6 +1063,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
|
|||
|
||||
this->underlyingChannel_ = underlyingChannel;
|
||||
|
||||
this->updateID();
|
||||
|
||||
this->performLayout();
|
||||
this->queueUpdate();
|
||||
|
||||
|
@ -1081,6 +1083,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
|
|||
void ChannelView::setFilters(const QList<QUuid> &ids)
|
||||
{
|
||||
this->channelFilters_ = std::make_shared<FilterSet>(ids);
|
||||
|
||||
this->updateID();
|
||||
}
|
||||
|
||||
QList<QUuid> ChannelView::getFilterIds() const
|
||||
|
@ -3237,4 +3241,27 @@ void ChannelView::pendingLinkInfoStateChanged()
|
|||
this->tooltipWidget_->applyLastBoundsCheck();
|
||||
}
|
||||
|
||||
void ChannelView::updateID()
|
||||
{
|
||||
if (!this->underlyingChannel_)
|
||||
{
|
||||
// cannot update
|
||||
return;
|
||||
}
|
||||
|
||||
std::size_t seed = 0;
|
||||
auto first = qHash(this->underlyingChannel_->getName());
|
||||
auto second = qHash(this->getFilterIds());
|
||||
|
||||
boost::hash_combine(seed, first);
|
||||
boost::hash_combine(seed, second);
|
||||
|
||||
this->id_ = seed;
|
||||
}
|
||||
|
||||
ChannelView::ChannelViewID ChannelView::getID() const
|
||||
{
|
||||
return this->id_;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -215,6 +215,9 @@ public:
|
|||
|
||||
Scrollbar *scrollbar();
|
||||
|
||||
using ChannelViewID = std::size_t;
|
||||
ChannelViewID getID() const;
|
||||
|
||||
pajlada::Signals::Signal<QMouseEvent *> mouseDown;
|
||||
pajlada::Signals::NoArgSignal selectionChanged;
|
||||
pajlada::Signals::Signal<HighlightState, const MessagePtr &>
|
||||
|
@ -318,6 +321,9 @@ private:
|
|||
void showReplyThreadPopup(const MessagePtr &message);
|
||||
bool canReplyToMessages() const;
|
||||
|
||||
void updateID();
|
||||
ChannelViewID id_{};
|
||||
|
||||
bool layoutQueued_ = false;
|
||||
bool bufferInvalidationQueued_ = false;
|
||||
|
||||
|
|
|
@ -56,27 +56,6 @@ namespace {
|
|||
}
|
||||
} // namespace
|
||||
|
||||
std::size_t NotebookTab::HighlightSources::ChannelViewProxyHash::operator()(
|
||||
const ChannelViewProxy &cp) const noexcept
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
auto first = qHash(cp.channelView->underlyingChannel()->getName());
|
||||
auto second = qHash(cp.channelView->getFilterIds());
|
||||
|
||||
boost::hash_combine(seed, first);
|
||||
boost::hash_combine(seed, second);
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
bool NotebookTab::HighlightSources::ChannelViewProxyEqual::operator()(
|
||||
const ChannelViewProxy &lp, const ChannelViewProxy &rp) const
|
||||
{
|
||||
return lp.channelView->underlyingChannel() ==
|
||||
rp.channelView->underlyingChannel() &&
|
||||
lp.channelView->getFilterIds() == rp.channelView->getFilterIds();
|
||||
}
|
||||
|
||||
NotebookTab::NotebookTab(Notebook *notebook)
|
||||
: Button(notebook)
|
||||
, positionChangedAnimation_(this, "pos")
|
||||
|
@ -327,13 +306,13 @@ bool NotebookTab::isSelected() const
|
|||
}
|
||||
|
||||
void NotebookTab::removeNewMessageSource(
|
||||
const HighlightSources::ChannelViewProxy &source)
|
||||
const ChannelView::ChannelViewID &source)
|
||||
{
|
||||
this->highlightSources_.newMessageSource.erase(source);
|
||||
}
|
||||
|
||||
void NotebookTab::removeHighlightedSource(
|
||||
const HighlightSources::ChannelViewProxy &source)
|
||||
const ChannelView::ChannelViewID &source)
|
||||
{
|
||||
this->highlightSources_.highlightedSource.erase(source);
|
||||
}
|
||||
|
@ -354,11 +333,9 @@ void NotebookTab::removeHighlightStateChangeSources(
|
|||
|
||||
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
|
||||
{
|
||||
auto channelViewProxy =
|
||||
HighlightSources::ChannelViewProxy{&channelViewSource};
|
||||
auto sourceChannel = channelViewSource.underlyingChannel();
|
||||
this->removeHighlightedSource(channelViewProxy);
|
||||
this->removeNewMessageSource(channelViewProxy);
|
||||
auto channelViewId = channelViewSource.getID();
|
||||
this->removeHighlightedSource(channelViewId);
|
||||
this->removeNewMessageSource(channelViewId);
|
||||
this->updateHighlightStateDueSourcesChange();
|
||||
|
||||
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
|
||||
|
@ -373,8 +350,8 @@ void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
|
|||
auto *tab = splitContainer->getTab();
|
||||
if (tab && tab != this)
|
||||
{
|
||||
tab->removeHighlightedSource(channelViewProxy);
|
||||
tab->removeNewMessageSource(channelViewProxy);
|
||||
tab->removeHighlightedSource(channelViewId);
|
||||
tab->removeNewMessageSource(channelViewId);
|
||||
tab->updateHighlightStateDueSourcesChange();
|
||||
}
|
||||
}
|
||||
|
@ -576,32 +553,23 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
|
|||
|
||||
// message is highlighting unvisible tab
|
||||
|
||||
auto underlyingChannel = channelViewSource.underlyingChannel();
|
||||
auto newFilters = channelViewSource.getFilterIds();
|
||||
auto channelViewProxy =
|
||||
HighlightSources::ChannelViewProxy{&channelViewSource};
|
||||
|
||||
// the unvisible tab should unhighlight other tabs iff
|
||||
// the other tab's filters are more generic therefore
|
||||
// the other tab's filter set is subset of the unvisible tab
|
||||
auto channelViewId = channelViewSource.getID();
|
||||
|
||||
switch (newHighlightStyle)
|
||||
{
|
||||
case HighlightState::Highlighted: {
|
||||
if (!this->highlightSources_.highlightedSource.contains(
|
||||
channelViewProxy))
|
||||
channelViewId))
|
||||
{
|
||||
this->highlightSources_.highlightedSource.insert(
|
||||
channelViewProxy);
|
||||
this->highlightSources_.highlightedSource.insert(channelViewId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case HighlightState::NewMessage: {
|
||||
if (!this->highlightSources_.newMessageSource.contains(
|
||||
channelViewProxy))
|
||||
channelViewId))
|
||||
{
|
||||
this->highlightSources_.newMessageSource.insert(
|
||||
channelViewProxy);
|
||||
this->highlightSources_.newMessageSource.insert(channelViewId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -126,40 +126,19 @@ private:
|
|||
const MessagePtr &message) const;
|
||||
|
||||
struct HighlightSources {
|
||||
struct ChannelViewProxy {
|
||||
const ChannelView *channelView;
|
||||
};
|
||||
|
||||
struct ChannelViewProxyHash {
|
||||
using is_transparent = void;
|
||||
std::size_t operator()(const ChannelViewProxy &cp) const noexcept;
|
||||
};
|
||||
|
||||
struct ChannelViewProxyEqual {
|
||||
bool operator()(const ChannelViewProxy &l,
|
||||
const ChannelViewProxy &r) const;
|
||||
};
|
||||
|
||||
std::unordered_set<ChannelViewProxy, ChannelViewProxyHash,
|
||||
ChannelViewProxyEqual>
|
||||
newMessageSource;
|
||||
std::unordered_set<ChannelViewProxy, ChannelViewProxyHash,
|
||||
ChannelViewProxyEqual>
|
||||
highlightedSource;
|
||||
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 removeNewMessageSource(
|
||||
const HighlightSources::ChannelViewProxy &source);
|
||||
void removeHighlightedSource(
|
||||
const HighlightSources::ChannelViewProxy &source);
|
||||
void removeNewMessageSource(const ChannelView::ChannelViewID &source);
|
||||
void removeHighlightedSource(const ChannelView::ChannelViewID &source);
|
||||
void updateHighlightStateDueSourcesChange();
|
||||
|
||||
QPropertyAnimation positionChangedAnimation_;
|
||||
|
|
Loading…
Reference in a new issue