Compare commits

...

21 commits

Author SHA1 Message Date
hemirt c8a40ae5d1
Merge af3d46fe25 into 867e3f3ab0 2024-10-21 00:57:41 +02:00
unknown af3d46fe25 add boost hash include 2024-10-20 18:45:34 +02:00
hemirt 49caab7e7c
Merge branch 'Chatterino:master' into master 2024-10-20 18:26:51 +02:00
unknown ef2647fe05 treat filters as special channels that should highlight always 2024-10-20 18:23:21 +02:00
unknown b0e3a41312 message shown based inclusion 2024-10-20 18:04:24 +02:00
unknown fe51ba85e7 hash based matching based on ChannelView name and filters 2024-10-20 17:46:22 +02:00
unknown 2884c828b0 update highlights of other tabs when adding new channel or changing
channel
2024-10-18 09:24:34 +02:00
unknown e288742360 more asserts 2024-10-17 20:43:25 +02:00
unknown 1ca5d38ad5 add some asserts 2024-10-17 20:35:52 +02:00
unknown 39e0e00f2d add more highlight state functions 2024-10-17 20:05:05 +02:00
unknown 8745d0740f fix duplicating tabs 2024-10-17 19:24:53 +02:00
unknown 5f862c5e5e solve highlighted tabs 2024-10-17 18:56:14 +02:00
unknown a2af8e791b switch from QHash to std::unordered_map 2024-10-17 17:25:54 +02:00
unknown 13d7692a89 add older version code 2024-10-17 16:38:32 +02:00
unknown 806fa7790d missing include 2024-10-17 15:37:36 +02:00
unknown edaafac010 initial state of selecting to unhiglight 2024-10-17 13:16:37 +02:00
unknown 7728f01916 name fixes 2024-10-15 18:14:11 +02:00
hemirt 70f497d3bd
Update src/widgets/helper/NotebookTab.cpp
Co-authored-by: nerix <nero.9@hotmail.de>
2024-10-15 18:03:14 +02:00
unknown 3b64f142e6 commit suggestions 2024-10-15 02:46:19 +02:00
unknown e827097c1c fix suggestions 2024-10-15 01:10:24 +02:00
unknown f7dd6de872 highlight tabs only on unviewed messages 2024-10-15 01:10:24 +02:00
7 changed files with 344 additions and 19 deletions

View file

@ -204,7 +204,7 @@ void Notebook::duplicatePage(QWidget *page)
{ {
newTabPosition = tabPosition + 1; newTabPosition = tabPosition + 1;
} }
auto newTabHighlightState = item->tab->highlightState();
QString newTabTitle = ""; QString newTabTitle = "";
if (item->tab->hasCustomTitle()) if (item->tab->hasCustomTitle())
{ {
@ -213,7 +213,7 @@ void Notebook::duplicatePage(QWidget *page)
auto *tab = auto *tab =
this->addPageAt(newContainer, newTabPosition, newTabTitle, false); this->addPageAt(newContainer, newTabPosition, newTabTitle, false);
tab->setHighlightState(newTabHighlightState); tab->copyHighlightStateAndSourcesFrom(item->tab);
newContainer->setTab(tab); newContainer->setTab(tab);
} }

View file

@ -2,6 +2,7 @@
#include "widgets/BaseWidget.hpp" #include "widgets/BaseWidget.hpp"
#include <ForwardDecl.hpp>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp> #include <pajlada/signals/signalholder.hpp>
#include <QList> #include <QList>

View file

@ -1190,11 +1190,13 @@ void ChannelView::messageAppended(MessagePtr &message,
(this->channel_->getType() == Channel::Type::TwitchAutomod && (this->channel_->getType() == Channel::Type::TwitchAutomod &&
getSettings()->enableAutomodHighlight)) getSettings()->enableAutomodHighlight))
{ {
this->tabHighlightRequested.invoke(HighlightState::Highlighted); this->tabHighlightRequested.invoke(HighlightState::Highlighted,
message);
} }
else else
{ {
this->tabHighlightRequested.invoke(HighlightState::NewMessage); this->tabHighlightRequested.invoke(HighlightState::NewMessage,
message);
} }
} }

View file

@ -179,6 +179,9 @@ public:
LimitedQueueSnapshot<MessageLayoutPtr> &getMessagesSnapshot(); LimitedQueueSnapshot<MessageLayoutPtr> &getMessagesSnapshot();
// Returns true if message should be included
bool shouldIncludeMessage(const MessagePtr &m) const;
void queueLayout(); void queueLayout();
void invalidateBuffers(); void invalidateBuffers();
@ -214,7 +217,8 @@ public:
pajlada::Signals::Signal<QMouseEvent *> mouseDown; pajlada::Signals::Signal<QMouseEvent *> mouseDown;
pajlada::Signals::NoArgSignal selectionChanged; pajlada::Signals::NoArgSignal selectionChanged;
pajlada::Signals::Signal<HighlightState> tabHighlightRequested; pajlada::Signals::Signal<HighlightState, const MessagePtr &>
tabHighlightRequested;
pajlada::Signals::NoArgSignal liveStatusChanged; pajlada::Signals::NoArgSignal liveStatusChanged;
pajlada::Signals::Signal<const Link &> linkClicked; pajlada::Signals::Signal<const Link &> linkClicked;
pajlada::Signals::Signal<QString, FromTwitchLinkOpenChannelIn> pajlada::Signals::Signal<QString, FromTwitchLinkOpenChannelIn>
@ -374,9 +378,6 @@ private:
FilterSetPtr channelFilters_; FilterSetPtr channelFilters_;
// Returns true if message should be included
bool shouldIncludeMessage(const MessagePtr &m) const;
// Returns whether the scrollbar should have highlights // Returns whether the scrollbar should have highlights
bool showScrollbarHighlights() const; bool showScrollbarHighlights() const;

View file

@ -1,6 +1,7 @@
#include "widgets/helper/NotebookTab.hpp" #include "widgets/helper/NotebookTab.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Channel.hpp"
#include "common/Common.hpp" #include "common/Common.hpp"
#include "controllers/hotkeys/HotkeyCategory.hpp" #include "controllers/hotkeys/HotkeyCategory.hpp"
#include "controllers/hotkeys/HotkeyController.hpp" #include "controllers/hotkeys/HotkeyController.hpp"
@ -12,9 +13,11 @@
#include "widgets/dialogs/SettingsDialog.hpp" #include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/Notebook.hpp" #include "widgets/Notebook.hpp"
#include "widgets/splits/DraggedSplit.hpp" #include "widgets/splits/DraggedSplit.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/splits/SplitContainer.hpp" #include "widgets/splits/SplitContainer.hpp"
#include <boost/bind/bind.hpp> #include <boost/bind/bind.hpp>
#include <boost/container_hash/hash.hpp>
#include <QAbstractAnimation> #include <QAbstractAnimation>
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
@ -53,6 +56,27 @@ namespace {
} }
} // 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) NotebookTab::NotebookTab(Notebook *notebook)
: Button(notebook) : Button(notebook)
, positionChangedAnimation_(this, "pos") , positionChangedAnimation_(this, "pos")
@ -302,10 +326,146 @@ bool NotebookTab::isSelected() const
return this->selected_; return this->selected_;
} }
void NotebookTab::removeNewMessageSource(
const HighlightSources::ChannelViewProxy &source)
{
this->highlightSources_.newMessageSource.erase(source);
}
void NotebookTab::removeHighlightedSource(
const HighlightSources::ChannelViewProxy &source)
{
this->highlightSources_.highlightedSource.erase(source);
}
void NotebookTab::removeHighlightStateChangeSources(
const HighlightSources &toRemove)
{
for (const auto &source : toRemove.newMessageSource)
{
this->removeNewMessageSource(source);
}
for (const auto &source : toRemove.highlightedSource)
{
this->removeHighlightedSource(source);
}
}
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
{
auto channelViewProxy =
HighlightSources::ChannelViewProxy{&channelViewSource};
auto sourceChannel = channelViewSource.underlyingChannel();
this->removeHighlightedSource(channelViewProxy);
this->removeNewMessageSource(channelViewProxy);
this->updateHighlightStateDueSourcesChange();
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->removeHighlightedSource(channelViewProxy);
tab->removeNewMessageSource(channelViewProxy);
tab->updateHighlightStateDueSourcesChange();
}
}
}
}
}
void NotebookTab::updateHighlightStateDueSourcesChange()
{
if (!this->highlightSources_.highlightedSource.empty())
{
assert(this->highlightState_ == HighlightState::Highlighted);
return;
}
if (!this->highlightSources_.newMessageSource.empty())
{
if (this->highlightState_ != HighlightState::NewMessage)
{
this->highlightState_ = HighlightState::NewMessage;
this->update();
}
}
else
{
if (this->highlightState_ != HighlightState::None)
{
this->highlightState_ = HighlightState::None;
this->update();
}
}
assert(this->highlightState_ != HighlightState::Highlighted);
}
void NotebookTab::copyHighlightStateAndSourcesFrom(const NotebookTab *sourceTab)
{
if (this->isSelected())
{
assert(this->highlightSources_.highlightedSource.empty());
assert(this->highlightSources_.newMessageSource.empty());
assert(this->highlightState_ == HighlightState::None);
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) void NotebookTab::setSelected(bool value)
{ {
this->selected_ = value; this->selected_ = value;
if (value)
{
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->removeHighlightStateChangeSources(
this->highlightSources_);
tab->updateHighlightStateDueSourcesChange();
}
}
}
}
}
this->highlightSources_.clear();
this->highlightState_ = HighlightState::None; this->highlightState_ = HighlightState::None;
this->update(); this->update();
@ -358,13 +518,91 @@ bool NotebookTab::isLive() const
return this->isLive_; return this->isLive_;
} }
HighlightState NotebookTab::highlightState() const
{
return this->highlightState_;
}
void NotebookTab::setHighlightState(HighlightState newHighlightStyle) void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
{ {
if (this->isSelected()) if (this->isSelected())
{ {
assert(this->highlightSources_.highlightedSource.empty());
assert(this->highlightSources_.newMessageSource.empty());
assert(this->highlightState_ == HighlightState::None);
return; return;
} }
this->highlightSources_.clear();
if (!this->highlightEnabled_ &&
newHighlightStyle == HighlightState::NewMessage)
{
return;
}
if (this->highlightState_ == newHighlightStyle ||
this->highlightState_ == HighlightState::Highlighted)
{
return;
}
this->highlightState_ = newHighlightStyle;
this->update();
}
void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
const ChannelView &channelViewSource,
const MessagePtr &message)
{
if (this->isSelected())
{
assert(this->highlightSources_.highlightedSource.empty());
assert(this->highlightSources_.newMessageSource.empty());
assert(this->highlightState_ == HighlightState::None);
return;
}
if (!this->shouldMessageHighlight(channelViewSource, message))
{
return;
}
// 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
switch (newHighlightStyle)
{
case HighlightState::Highlighted: {
if (!this->highlightSources_.highlightedSource.contains(
channelViewProxy))
{
this->highlightSources_.highlightedSource.insert(
channelViewProxy);
}
break;
}
case HighlightState::NewMessage: {
if (!this->highlightSources_.newMessageSource.contains(
channelViewProxy))
{
this->highlightSources_.newMessageSource.insert(
channelViewProxy);
}
break;
}
case HighlightState::None:
break;
}
if (!this->highlightEnabled_ && if (!this->highlightEnabled_ &&
newHighlightStyle == HighlightState::NewMessage) newHighlightStyle == HighlightState::NewMessage)
{ {
@ -381,9 +619,28 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
this->update(); this->update();
} }
HighlightState NotebookTab::highlightState() const bool NotebookTab::shouldMessageHighlight(const ChannelView &channelViewSource,
const MessagePtr &message) const
{ {
return this->highlightState_; auto *visibleSplitContainer =
dynamic_cast<SplitContainer *>(this->notebook_->getSelectedPage());
if (visibleSplitContainer != nullptr)
{
const auto &visibleSplits = visibleSplitContainer->getSplits();
for (const auto &visibleSplit : visibleSplits)
{
if (channelViewSource.underlyingChannel() ==
visibleSplit->getChannel() &&
visibleSplit->getChannelView().shouldIncludeMessage(message) &&
channelViewSource.shouldIncludeMessage(message) &&
channelViewSource.getFilterIds().empty())
{
return false;
}
}
}
return true;
} }
void NotebookTab::setHighlightsEnabled(const bool &newVal) void NotebookTab::setHighlightsEnabled(const bool &newVal)

View file

@ -2,6 +2,7 @@
#include "common/Common.hpp" #include "common/Common.hpp"
#include "widgets/helper/Button.hpp" #include "widgets/helper/Button.hpp"
#include "widgets/helper/ChannelView.hpp"
#include "widgets/Notebook.hpp" #include "widgets/Notebook.hpp"
#include <pajlada/settings/setting.hpp> #include <pajlada/settings/setting.hpp>
@ -59,11 +60,25 @@ public:
**/ **/
bool isLive() const; bool isLive() const;
/**
* @brief Sets the highlight state of this tab clearing highlight sources
*
* Obeys the HighlightsEnabled setting and highlight states hierarchy
*/
void setHighlightState(HighlightState style); void setHighlightState(HighlightState style);
HighlightState highlightState() const; /**
* @brief Updates the highlight state and highlight sources of this tab
*
* Obeys the HighlightsEnabled setting and the highlight state hierarchy and tracks the highlight state update sources
*/
void updateHighlightState(HighlightState style,
const ChannelView &channelViewSource,
const MessagePtr &message);
void copyHighlightStateAndSourcesFrom(const NotebookTab *sourceTab);
void setHighlightsEnabled(const bool &newVal); void setHighlightsEnabled(const bool &newVal);
void newHighlightSourceAdded(const ChannelView &channelViewSource);
bool hasHighlightsEnabled() const; bool hasHighlightsEnabled() const;
HighlightState highlightState() const;
void moveAnimated(QPoint targetPos, bool animated = true); void moveAnimated(QPoint targetPos, bool animated = true);
@ -107,6 +122,46 @@ private:
int normalTabWidthForHeight(int height) const; int normalTabWidthForHeight(int height) const;
bool shouldMessageHighlight(const ChannelView &channelViewSource,
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;
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 updateHighlightStateDueSourcesChange();
QPropertyAnimation positionChangedAnimation_; QPropertyAnimation positionChangedAnimation_;
QPoint positionAnimationDesiredPoint_; QPoint positionAnimationDesiredPoint_;

View file

@ -213,11 +213,20 @@ void SplitContainer::addSplit(Split *split)
auto &&conns = this->connectionsPerSplit_[split]; auto &&conns = this->connectionsPerSplit_[split];
conns.managedConnect(split->getChannelView().tabHighlightRequested, conns.managedConnect(
[this](HighlightState state) { split->getChannelView().tabHighlightRequested,
[this, split](HighlightState state, const MessagePtr &message) {
if (this->tab_ != nullptr) if (this->tab_ != nullptr)
{ {
this->tab_->setHighlightState(state); this->tab_->updateHighlightState(state, split->getChannelView(),
message);
}
});
conns.managedConnect(split->channelChanged, [this, split] {
if (this->tab_ != nullptr)
{
this->tab_->newHighlightSourceAdded(split->getChannelView());
} }
}); });