From 6b483640cdf399b91f99b7cb342fe0d0cf55b83a Mon Sep 17 00:00:00 2001 From: fourtf Date: Mon, 5 Feb 2018 23:32:38 +0100 Subject: [PATCH] added username in the titlebar --- src/widgets/basewindow.cpp | 15 ++++++++++++++- src/widgets/basewindow.hpp | 2 ++ src/widgets/window.cpp | 7 ++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/widgets/basewindow.cpp b/src/widgets/basewindow.cpp index 65bc21b2..c85bec6f 100644 --- a/src/widgets/basewindow.cpp +++ b/src/widgets/basewindow.cpp @@ -2,6 +2,7 @@ #include "singletons/settingsmanager.hpp" #include "util/nativeeventhelper.hpp" +#include "widgets/helper/rippleeffectlabel.hpp" #include "widgets/tooltipwidget.hpp" #include @@ -149,7 +150,6 @@ bool BaseWindow::hasCustomWindowFrame() { #ifdef Q_OS_WIN return this->enableCustomFrame; -// return false; #else return false; #endif @@ -182,6 +182,19 @@ void BaseWindow::addTitleBarButton(const TitleBarButton::Style &style, QObject::connect(button, &TitleBarButton::clicked, this, [onClicked] { onClicked(); }); } +RippleEffectLabel *BaseWindow::addTitleBarLabel(std::function onClicked) +{ + RippleEffectLabel *button = new RippleEffectLabel; + button->setScaleIndependantHeight(30); + + this->buttons.push_back(button); + this->titlebarBox->insertWidget(2, button); + + QObject::connect(button, &RippleEffectLabel::clicked, this, [onClicked] { onClicked(); }); + + return button; +} + void BaseWindow::changeEvent(QEvent *) { TooltipWidget::getInstance()->hide(); diff --git a/src/widgets/basewindow.hpp b/src/widgets/basewindow.hpp index fc6ccd75..3f4c3c0f 100644 --- a/src/widgets/basewindow.hpp +++ b/src/widgets/basewindow.hpp @@ -10,6 +10,7 @@ class QHBoxLayout; namespace chatterino { namespace widgets { class RippleEffectButton; +class RippleEffectLabel; class TitleBarButton; class BaseWindow : public BaseWidget @@ -23,6 +24,7 @@ public: QWidget *getLayoutContainer(); bool hasCustomWindowFrame(); void addTitleBarButton(const TitleBarButton::Style &style, std::function onClicked); + RippleEffectLabel *addTitleBarLabel(std::function onClicked); void setStayInScreenRect(bool value); bool getStayInScreenRect() const; diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index d83dd481..29f7d4a5 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -39,9 +39,14 @@ Window::Window(const QString &windowName, singletons::ThemeManager &_themeManage this->addTitleBarButton(TitleBarButton::Settings, [] { singletons::WindowManager::getInstance().showSettingsDialog(); }); - this->addTitleBarButton(TitleBarButton::User, [this] { + auto user = this->addTitleBarLabel([this] { singletons::WindowManager::getInstance().showAccountSelectPopup(QCursor::pos()); }); + + singletons::AccountManager::getInstance().Twitch.userChanged.connect([this, user] { + user->getLabel().setText( + singletons::AccountManager::getInstance().Twitch.getCurrent()->getUserName()); + }); } QVBoxLayout *layout = new QVBoxLayout(this);