From 91099c028edbb07ac2d41caa90d58b900a19a449 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 24 Dec 2017 16:01:01 +0100 Subject: [PATCH] moved the tooltip close logic to basewidget --- src/widgets/basewidget.cpp | 9 +++++++++ src/widgets/basewidget.hpp | 4 ++++ src/widgets/helper/channelview.cpp | 1 - src/widgets/window.cpp | 25 ++++++++++++------------- src/widgets/window.hpp | 7 ++++--- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/widgets/basewidget.cpp b/src/widgets/basewidget.cpp index a3f475a8d..69e5e78b7 100644 --- a/src/widgets/basewidget.cpp +++ b/src/widgets/basewidget.cpp @@ -1,6 +1,7 @@ #include "widgets/basewidget.hpp" #include "colorscheme.hpp" #include "settingsmanager.hpp" +#include "widgets/tooltipwidget.hpp" #include #include @@ -61,6 +62,8 @@ void BaseWidget::init() void BaseWidget::initAsWindow() { + this->isWindow = true; + #ifdef USEWINSDK auto dpi = util::getWindowDpi(this->winId()); @@ -101,5 +104,11 @@ bool BaseWidget::nativeEvent(const QByteArray &eventType, void *message, long *r } #endif +void BaseWidget::focusOutEvent(QFocusEvent *) +{ + if (this->isWindow) { + TooltipWidget::getInstance()->hide(); + } +} } // namespace widgets } // namespace chatterino diff --git a/src/widgets/basewidget.hpp b/src/widgets/basewidget.hpp index 47db2b4a6..98c433bf4 100644 --- a/src/widgets/basewidget.hpp +++ b/src/widgets/basewidget.hpp @@ -28,13 +28,17 @@ protected: virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; #endif + virtual void focusOutEvent(QFocusEvent *) override; + // XXX: Should this be pure virtual? + // fourtf: hell no virtual void dpiMultiplierChanged(float /*oldDpi*/, float /*newDpi*/) { } void initAsWindow(); private: + bool isWindow = false; float dpiMultiplier = 1.f; void init(); diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 9bbd58ffc..6290792f1 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -82,7 +82,6 @@ ChannelView::ChannelView(BaseWidget *parent) Window *_window = dynamic_cast(this->window()); if (_window) { - _window->lostFocus.connect([this] { TooltipWidget::getInstance()->hide(); }); } } diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index 5f334404d..8254b63e2 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -107,20 +107,19 @@ void Window::closeEvent(QCloseEvent *) this->closed(); } -void Window::changeEvent(QEvent *event) -{ - if(!this->isActiveWindow()) - { - this->lostFocus.invoke(); - } - BaseWidget::changeEvent(event); -} +// void Window::changeEvent(QEvent *event) +//{ +// if (!this->isActiveWindow()) { +// this->lostFocus.invoke(); +// } +// BaseWidget::changeEvent(event); +//} -void Window::leaveEvent(QEvent *event) -{ - this->lostFocus.invoke(); - BaseWidget::leaveEvent(event); -} +// void Window::leaveEvent(QEvent *event) +//{ +// this->lostFocus.invoke(); +// BaseWidget::leaveEvent(event); +//} void Window::refreshTheme() { diff --git a/src/widgets/window.hpp b/src/widgets/window.hpp index 0a8a1058a..f7902857b 100644 --- a/src/widgets/window.hpp +++ b/src/widgets/window.hpp @@ -56,13 +56,14 @@ public: boost::signals2::signal closed; - pajlada::Signals::NoArgSignal lostFocus; + // pajlada::Signals::NoArgSignal lostFocus; protected: virtual void closeEvent(QCloseEvent *event) override; - virtual void changeEvent(QEvent *event) override; - virtual void leaveEvent(QEvent *event) override; + // virtual void changeEvent(QEvent *event) override; + // virtual void leaveEvent(QEvent *event) override; + private: float dpi;