From b2f454aca41e6b475fdda02b5528f5cda568a6ab Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 23 Jun 2018 11:54:00 +0000 Subject: [PATCH] Change header color when split is active Colors might need to change but they work for now Fix #495 --- src/providers/twitch/twitchserver.cpp | 1 - src/singletons/thememanager.cpp | 3 +-- src/singletons/thememanager.hpp | 1 + src/widgets/helper/resizingtextedit.cpp | 9 +++++++++ src/widgets/helper/resizingtextedit.hpp | 2 ++ src/widgets/helper/splitheader.cpp | 10 +++++++++- src/widgets/split.cpp | 1 + src/widgets/split.hpp | 1 + 8 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/providers/twitch/twitchserver.cpp b/src/providers/twitch/twitchserver.cpp index ac3b02575..113ec6e52 100644 --- a/src/providers/twitch/twitchserver.cpp +++ b/src/providers/twitch/twitchserver.cpp @@ -72,7 +72,6 @@ std::shared_ptr TwitchServer::createChannel(const QString &channelName) TwitchChannel *channel = new TwitchChannel(channelName, this->getReadConnection()); channel->sendMessageSignal.connect([this, channel](auto chan, auto msg, bool &sent) { - { std::lock_guard guard(this->lastMessageMutex); diff --git a/src/singletons/thememanager.cpp b/src/singletons/thememanager.cpp index f6cd517df..b344b7970 100644 --- a/src/singletons/thememanager.cpp +++ b/src/singletons/thememanager.cpp @@ -32,8 +32,6 @@ ThemeManager::ThemeManager() : themeName("/appearance/theme/name", "Dark") , themeHue("/appearance/theme/hue", 0.0) { - qDebug() << "init ThemeManager"; - this->update(); this->themeName.connectSimple([this](auto) { this->update(); }, false); @@ -168,6 +166,7 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier) this->splits.header.background = getColor(0, sat, flat ? 1 : 0.9); this->splits.header.border = getColor(0, sat, flat ? 1 : 0.85); this->splits.header.text = this->messages.textColors.regular; + this->splits.header.activeText = isLight ? QColor(134, 79, 242) : QColor(242, 209, 79); this->splits.input.background = getColor(0, sat, flat ? 0.95 : 0.95); this->splits.input.border = getColor(0, sat, flat ? 1 : 1); diff --git a/src/singletons/thememanager.hpp b/src/singletons/thememanager.hpp index cf6c2d10d..511684222 100644 --- a/src/singletons/thememanager.hpp +++ b/src/singletons/thememanager.hpp @@ -70,6 +70,7 @@ public: QColor border; QColor background; QColor text; + QColor activeText; // int margin; } header; diff --git a/src/widgets/helper/resizingtextedit.cpp b/src/widgets/helper/resizingtextedit.cpp index 752b1f236..3ca219a06 100644 --- a/src/widgets/helper/resizingtextedit.cpp +++ b/src/widgets/helper/resizingtextedit.cpp @@ -146,6 +146,15 @@ void ResizingTextEdit::focusInEvent(QFocusEvent *event) } } +void ResizingTextEdit::focusOutEvent(QFocusEvent *event) +{ + QTextEdit::focusOutEvent(event); + + if (event->lostFocus()) { + this->focusLost.invoke(); + } +} + void ResizingTextEdit::setCompleter(QCompleter *c) { if (this->completer) { diff --git a/src/widgets/helper/resizingtextedit.hpp b/src/widgets/helper/resizingtextedit.hpp index 736619772..4102ca00f 100644 --- a/src/widgets/helper/resizingtextedit.hpp +++ b/src/widgets/helper/resizingtextedit.hpp @@ -16,6 +16,7 @@ public: pajlada::Signals::Signal keyPressed; pajlada::Signals::NoArgSignal focused; + pajlada::Signals::NoArgSignal focusLost; void setCompleter(QCompleter *c); QCompleter *getCompleter() const; @@ -25,6 +26,7 @@ protected: void keyPressEvent(QKeyEvent *event) override; void focusInEvent(QFocusEvent *event) override; + void focusOutEvent(QFocusEvent *event) override; private: QCompleter *completer = nullptr; diff --git a/src/widgets/helper/splitheader.cpp b/src/widgets/helper/splitheader.cpp index 28d97e392..08abe9894 100644 --- a/src/widgets/helper/splitheader.cpp +++ b/src/widgets/helper/splitheader.cpp @@ -30,6 +30,9 @@ SplitHeader::SplitHeader(Split *_split) : BaseWidget(_split) , split(_split) { + this->split->focused.connect([this]() { this->themeRefreshEvent(); }); + this->split->focusLost.connect([this]() { this->themeRefreshEvent(); }); + auto app = getApp(); util::LayoutCreator layoutCreator(this); @@ -370,7 +373,12 @@ void SplitHeader::rightButtonClicked() void SplitHeader::themeRefreshEvent() { QPalette palette; - palette.setColor(QPalette::Foreground, this->themeManager->splits.header.text); + + if (this->split->hasFocus()) { + palette.setColor(QPalette::Foreground, this->themeManager->splits.header.activeText); + } else { + palette.setColor(QPalette::Foreground, this->themeManager->splits.header.text); + } // this->dropdownButton->setPalette(palette); this->titleLabel->setPalette(palette); diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp index a38922c08..2659a2b1c 100644 --- a/src/widgets/split.cpp +++ b/src/widgets/split.cpp @@ -143,6 +143,7 @@ Split::Split(QWidget *parent) }); this->input.ui_.textEdit->focused.connect([this] { this->focused.invoke(); }); + this->input.ui_.textEdit->focusLost.connect([this] { this->focusLost.invoke(); }); } Split::~Split() diff --git a/src/widgets/split.hpp b/src/widgets/split.hpp index 10cd942c6..07051145d 100644 --- a/src/widgets/split.hpp +++ b/src/widgets/split.hpp @@ -47,6 +47,7 @@ public: pajlada::Signals::NoArgSignal channelChanged; pajlada::Signals::NoArgSignal focused; + pajlada::Signals::NoArgSignal focusLost; ChannelView &getChannelView(); SplitContainer *getContainer();