From 13b39e374b1382ff263f8c847e39532ac4609d92 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Tue, 26 Dec 2017 12:32:24 +0100 Subject: [PATCH] Tabs now highlight when a highlight is received Work on #88 --- src/messages/message.cpp | 2 +- src/messages/message.hpp | 2 +- src/widgets/helper/channelview.cpp | 6 +++++- src/widgets/helper/channelview.hpp | 3 ++- src/widgets/helper/notebooktab.cpp | 6 ++++++ src/widgets/split.cpp | 2 +- src/widgets/split.hpp | 5 +++++ src/widgets/splitcontainer.cpp | 9 ++++++++- 8 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/messages/message.cpp b/src/messages/message.cpp index eee5d5de..4d7ddc3e 100644 --- a/src/messages/message.cpp +++ b/src/messages/message.cpp @@ -16,7 +16,7 @@ namespace chatterino { namespace messages { -bool Message::getCanHighlightTab() const +bool Message::containsHighlightedPhrase() const { return this->highlightTab; } diff --git a/src/messages/message.hpp b/src/messages/message.hpp index aa036749..d551df3e 100644 --- a/src/messages/message.hpp +++ b/src/messages/message.hpp @@ -18,7 +18,7 @@ typedef std::shared_ptr SharedMessage; class Message { public: - bool getCanHighlightTab() const; + bool containsHighlightedPhrase() const; void setHighlight(bool value); const QString &getTimeoutUser() const; int getTimeoutCount() const; diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 6290792f..696d7626 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -354,6 +354,10 @@ void ChannelView::setChannel(std::shared_ptr newChannel) } } + if (message->containsHighlightedPhrase()) { + this->highlightedMessageReceived.invoke(); + } + layoutMessages(); update(); }); @@ -533,7 +537,7 @@ void ChannelView::updateMessageBuffer(messages::MessageRef *messageRef, QPixmap // this->selectionMax.messageIndex >= messageIndex) { // painter.fillRect(buffer->rect(), QColor(24, 55, 25)); //} else { - painter.fillRect(buffer->rect(), (messageRef->getMessage()->getCanHighlightTab()) + painter.fillRect(buffer->rect(), (messageRef->getMessage()->containsHighlightedPhrase()) ? this->colorScheme.ChatBackgroundHighlighted : this->colorScheme.ChatBackground); //} diff --git a/src/widgets/helper/channelview.hpp b/src/widgets/helper/channelview.hpp index dd29224a..e3ec9b68 100644 --- a/src/widgets/helper/channelview.hpp +++ b/src/widgets/helper/channelview.hpp @@ -15,8 +15,8 @@ #include #include #include - #include +#include namespace chatterino { namespace widgets { @@ -103,6 +103,7 @@ public: boost::signals2::signal mouseDown; boost::signals2::signal selectionChanged; + pajlada::Signals::NoArgSignal highlightedMessageReceived; protected: virtual void resizeEvent(QResizeEvent *) override; diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index a2ba61ba..2e35f104 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -107,11 +107,17 @@ void NotebookTab::setSelected(bool value) { this->selected = value; + this->highlightState = HighlightState::None; + this->update(); } void NotebookTab::setHighlightState(HighlightState newHighlightStyle) { + if (this->isSelected()) { + return; + } + this->highlightState = newHighlightStyle; this->update(); diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp index b9c36400..6ddd98e0 100644 --- a/src/widgets/split.cpp +++ b/src/widgets/split.cpp @@ -277,7 +277,7 @@ void Split::doPopup() void Split::doClearChat() { - view.clearMessages(); + this->view.clearMessages(); } void Split::doOpenChannel() diff --git a/src/widgets/split.hpp b/src/widgets/split.hpp index 1e481f71..87d34972 100644 --- a/src/widgets/split.hpp +++ b/src/widgets/split.hpp @@ -53,6 +53,11 @@ public: pajlada::Settings::Setting channelName; boost::signals2::signal channelChanged; + ChannelView &getChannelView() + { + return this->view; + } + const std::string &getUUID() const; std::shared_ptr getChannel() const; std::shared_ptr &getChannelRef(); diff --git a/src/widgets/splitcontainer.cpp b/src/widgets/splitcontainer.cpp index ac20cb93..b207b279 100644 --- a/src/widgets/splitcontainer.cpp +++ b/src/widgets/splitcontainer.cpp @@ -1,5 +1,6 @@ #include "widgets/splitcontainer.hpp" #include "colorscheme.hpp" +#include "common.hpp" #include "util/helpers.hpp" #include "widgets/helper/notebooktab.hpp" #include "widgets/notebook.hpp" @@ -431,7 +432,13 @@ std::pair SplitContainer::getChatPosition(const Split *chatWidget) Split *SplitContainer::createChatWidget(const std::string &uuid) { - return new Split(this->channelManager, this, uuid); + auto split = new Split(this->channelManager, this, uuid); + + split->getChannelView().highlightedMessageReceived.connect([this] { + this->tab->setHighlightState(HighlightState::Highlighted); // + }); + + return split; } void SplitContainer::refreshTitle()