From 43d4cc46a14beb784202048ce6478e246a4a8de4 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 2 Dec 2023 11:02:02 +0100 Subject: [PATCH] fix: hopefully less build errors --- src/widgets/BaseWindow.cpp | 14 ++++++-- src/widgets/helper/TitlebarButtons.cpp | 49 ++++++++++++++++++-------- src/widgets/helper/TitlebarButtons.hpp | 15 +++++--- 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index f6d9dff01fb..d5c6e2b0e74 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -600,6 +600,11 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, break; case WM_NCMOUSEMOVE: { + if (!this->ui_.titlebarButtons) + { + break; + } + if (overButton()) { *result = 0; @@ -619,13 +624,16 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, break; case WM_NCMOUSELEAVE: { - this->ui_.titlebarButtons->leave(); + if (this->ui_.titlebarButtons) + { + this->ui_.titlebarButtons->leave(); + } } break; case WM_NCLBUTTONDOWN: case WM_NCLBUTTONUP: { - if (!overButton()) + if (!this->ui_.titlebarButtons || !overButton()) { break; } @@ -715,6 +723,7 @@ void BaseWindow::calcButtonsSizes() return; } +#ifdef USEWINSDK if ((static_cast(this->width()) / this->scale()) < 300) { this->ui_.titlebarButtons->setSmallSize(); @@ -723,6 +732,7 @@ void BaseWindow::calcButtonsSizes() { this->ui_.titlebarButtons->setRegularSize(); } +#endif } void BaseWindow::drawCustomWindowFrame(QPainter &painter) diff --git a/src/widgets/helper/TitlebarButtons.cpp b/src/widgets/helper/TitlebarButtons.cpp index 1b0811f04e3..4dcdf393261 100644 --- a/src/widgets/helper/TitlebarButtons.cpp +++ b/src/widgets/helper/TitlebarButtons.cpp @@ -20,13 +20,34 @@ TitleBarButtons::TitleBarButtons(QWidget *window, TitleBarButton *minButton, void TitleBarButtons::hover(size_t ht, QPoint at) { - auto [button, others] = this->buttonForHt(ht); - button->ncEnter(); - button->ncMove(button->mapFromGlobal(at)); - for (auto *other : others) + TitleBarButton *hovered{}; + TitleBarButton *other1{}; + TitleBarButton *other2{}; + switch (ht) { - other->ncLeave(); + case HTMAXBUTTON: + hovered = this->maxButton_; + other1 = this->minButton_; + other2 = this->closeButton_; + break; + case HTMINBUTTON: + hovered = this->minButton_; + other1 = this->maxButton_; + other2 = this->closeButton_; + break; + case HTCLOSE: + hovered = this->closeButton_; + other1 = this->minButton_; + other2 = this->maxButton_; + break; + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "Precondition violated"); + return; } + hovered->ncEnter(); + hovered->ncMove(hovered->mapFromGlobal(at)); + other1->ncLeave(); + other2->ncLeave(); } void TitleBarButtons::leave() @@ -38,13 +59,13 @@ void TitleBarButtons::leave() void TitleBarButtons::mouseDown(size_t ht, QPoint at) { - auto [button, others] = this->buttonForHt(ht); + auto *button = this->buttonForHt(ht); button->ncMouseDown(button->mapFromGlobal(at)); } void TitleBarButtons::mouseUp(size_t ht, QPoint at) { - auto [button, others] = this->buttonForHt(ht); + auto *button = this->buttonForHt(ht); button->ncMouseUp(button->mapFromGlobal(at)); } @@ -70,21 +91,19 @@ void TitleBarButtons::setRegularSize() this->closeButton_->setScaleIndependantSize(46, 30); } -std::pair> - TitleBarButtons::buttonForHt(size_t ht) const +TitleBarButton *TitleBarButtons::buttonForHt(size_t ht) const { switch (ht) { case HTMAXBUTTON: - return {this->maxButton_, {this->minButton_, this->closeButton_}}; + return this->maxButton_; case HTMINBUTTON: - return {this->minButton_, {this->maxButton_, this->closeButton_}}; + return this->minButton_; case HTCLOSE: - return {this->closeButton_, {this->minButton_, this->maxButton_}}; + return this->closeButton_; default: - Q_ASSERT_X(false, Q_FUNC_INFO, "No button for hittest value found"); - return {this->closeButton_, - {this->minButton_, this->maxButton_}}; // fallback + Q_ASSERT_X(false, Q_FUNC_INFO, "Precondition violated"); + return nullptr; } } diff --git a/src/widgets/helper/TitlebarButtons.hpp b/src/widgets/helper/TitlebarButtons.hpp index d3154bad59b..138dd03f3a0 100644 --- a/src/widgets/helper/TitlebarButtons.hpp +++ b/src/widgets/helper/TitlebarButtons.hpp @@ -5,8 +5,6 @@ class QWidget; #include -#include - namespace chatterino { #ifdef USEWINSDK @@ -18,9 +16,18 @@ class TitleBarButtons : QObject TitleBarButtons(QWidget *window, TitleBarButton *minButton, TitleBarButton *maxButton, TitleBarButton *closeButton); + /// @pre ht must be one of { HTMAXBUTTON, HTMINBUTTON, HTCLOSE }. + /// @param at The global position of the event void hover(size_t ht, QPoint at); + void leave(); + + /// @pre ht must be one of { HTMAXBUTTON, HTMINBUTTON, HTCLOSE }. + /// @param at The global position of the event void mouseDown(size_t ht, QPoint at); + + /// @pre ht must be one of { HTMAXBUTTON, HTMINBUTTON, HTCLOSE }. + /// @param at The global position of the event void mouseUp(size_t ht, QPoint at); void updateMaxButton(); @@ -29,8 +36,8 @@ class TitleBarButtons : QObject void setRegularSize(); private: - std::pair> buttonForHt( - size_t ht) const; + /// @pre ht must be one of { HTMAXBUTTON, HTMINBUTTON, HTCLOSE }. + TitleBarButton *buttonForHt(size_t ht) const; QWidget *window_ = nullptr; TitleBarButton *minButton_ = nullptr;