Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom highlight color in tabs #5579

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions src/controllers/highlights/HighlightPhrase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace {

} // namespace

// change made but removed in merge conflict
// QColor HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR = QColor(238, 97, 102, 65);
QColor HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR = QColor(127, 63, 73, 127);
QColor HighlightPhrase::FALLBACK_SELF_MESSAGE_HIGHLIGHT_COLOR =
QColor(0, 118, 221, 115);
Expand Down
6 changes: 4 additions & 2 deletions src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,11 +1176,13 @@ void ChannelView::messageAppended(MessagePtr &message,
(this->channel_->getType() == Channel::Type::TwitchAutomod &&
getSettings()->enableAutomodHighlight))
{
this->tabHighlightRequested.invoke(HighlightState::Highlighted);
this->tabHighlightRequested.invoke(HighlightState::Highlighted,
message->highlightColor);
}
else
{
this->tabHighlightRequested.invoke(HighlightState::NewMessage);
this->tabHighlightRequested.invoke(HighlightState::NewMessage,
nullptr);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/widgets/helper/ChannelView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "widgets/TooltipWidget.hpp"

#include <pajlada/signals/signal.hpp>
#include <QColor>
#include <QGestureEvent>
#include <QMenu>
#include <QPaintEvent>
Expand All @@ -21,6 +22,7 @@
#include <QWheelEvent>
#include <QWidget>

#include <memory>
#include <unordered_map>
#include <unordered_set>

Expand Down Expand Up @@ -193,7 +195,8 @@ class ChannelView final : public BaseWidget

pajlada::Signals::Signal<QMouseEvent *> mouseDown;
pajlada::Signals::NoArgSignal selectionChanged;
pajlada::Signals::Signal<HighlightState> tabHighlightRequested;
pajlada::Signals::Signal<HighlightState, std::shared_ptr<QColor>>
tabHighlightRequested;
pajlada::Signals::NoArgSignal liveStatusChanged;
pajlada::Signals::Signal<const Link &> linkClicked;
pajlada::Signals::Signal<QString, FromTwitchLinkOpenChannelIn>
Expand Down
18 changes: 18 additions & 0 deletions src/widgets/helper/NotebookTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ void NotebookTab::setSelected(bool value)
this->selected_ = value;

this->highlightState_ = HighlightState::None;
this->highlightColor_ = nullptr;

this->update();
}
Expand Down Expand Up @@ -397,6 +398,15 @@ bool NotebookTab::hasHighlightsEnabled() const
return this->highlightEnabled_;
}

void NotebookTab::setHighlightColor(std::shared_ptr<QColor> color)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the parameter 'color' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
void NotebookTab::setHighlightColor(std::shared_ptr<QColor> color)
void NotebookTab::setHighlightColor(const std::shared_ptr<QColor>& color)

src/widgets/helper/NotebookTab.hpp:67:

-     void setHighlightColor(std::shared_ptr<QColor> color);
+     void setHighlightColor(const std::shared_ptr<QColor>& color);

{
if (this->highlightColor_ != color)
{
this->highlightColor_ = color;
this->update();
}
}

QRect NotebookTab::getDesiredRect() const
{
return QRect(this->positionAnimationDesiredPoint_, size());
Expand Down Expand Up @@ -504,6 +514,14 @@ void NotebookTab::paintEvent(QPaintEvent *)
: (windowFocused ? colors.line.regular
: colors.line.unfocused);

if (this->highlightState_ == HighlightState::Highlighted &&
this->highlightColor_ != nullptr)
{
QColor col = *this->highlightColor_;
col.setAlpha(255);
lineColor = col;
}

QRect lineRect;
switch (this->tabLocation_)
{
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/helper/NotebookTab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <pajlada/settings/setting.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <QColor>
#include <QMenu>
#include <QPropertyAnimation>

Expand Down Expand Up @@ -64,6 +65,7 @@ class NotebookTab : public Button

void setHighlightsEnabled(const bool &newVal);
bool hasHighlightsEnabled() const;
void setHighlightColor(std::shared_ptr<QColor> color);

void moveAnimated(QPoint targetPos, bool animated = true);

Expand Down Expand Up @@ -127,6 +129,7 @@ class NotebookTab : public Button
HighlightState highlightState_ = HighlightState::None;
bool highlightEnabled_ = true;
QAction *highlightNewMessagesAction_;
std::shared_ptr<QColor> highlightColor_;

bool isLive_{};
bool isRerun_{};
Expand Down
20 changes: 13 additions & 7 deletions src/widgets/splits/SplitContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,19 @@ void SplitContainer::addSplit(Split *split)

auto &&conns = this->connectionsPerSplit_[split];

conns.managedConnect(split->getChannelView().tabHighlightRequested,
[this](HighlightState state) {
if (this->tab_ != nullptr)
{
this->tab_->setHighlightState(state);
}
});
conns.managedConnect(
split->getChannelView().tabHighlightRequested,
[this](HighlightState state, std::shared_ptr<QColor> color) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the parameter 'color' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
[this](HighlightState state, std::shared_ptr<QColor> color) {
[this](HighlightState state, const std::shared_ptr<QColor>& color) {

if (this->tab_ != nullptr)
{
this->tab_->setHighlightState(state);

if (color != nullptr)
{
this->tab_->setHighlightColor(color);
}
}
});

conns.managedConnect(split->getChannelView().liveStatusChanged, [this]() {
this->refreshTabLiveStatus();
Expand Down
Loading