From 95b1f826206086eab1e704ab816eb6fd1a4c3887 Mon Sep 17 00:00:00 2001 From: nerix Date: Sat, 7 Jan 2023 11:41:39 +0100 Subject: [PATCH] Remove Deprecated `QDesktopWidget` (#4287) * fix: remove deprecated `QDesktopWidget` * chore: add changelog entry --- CHANGELOG.md | 1 + src/singletons/WindowManager.cpp | 1 - src/widgets/BaseWindow.cpp | 46 +++++++++++------------ src/widgets/BaseWindow.hpp | 2 +- src/widgets/dialogs/NotificationPopup.cpp | 1 - src/widgets/helper/Button.cpp | 11 ++++-- src/widgets/splits/SplitHeader.cpp | 1 - 7 files changed, 33 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5e6e3a23..933d26169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - Dev: Removed unused include directives. (#4266, #4275) - Dev: Removed TooltipPreviewImage. (#4268) - Dev: Removed unused operators in `Image` (#4267) +- Dev: Removed usage of deprecated `QDesktopWidget` (#4287) ## 2.4.0 diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index cc074dd0f..15053ccd1 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index 070a2533a..2c7da463b 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -12,9 +12,9 @@ #include "widgets/TooltipWidget.hpp" #include -#include #include #include +#include #include @@ -244,7 +244,7 @@ void BaseWindow::setStayInScreenRect(bool value) { this->stayInScreenRect_ = value; - this->moveIntoDesktopRect(this, this->pos()); + this->moveIntoDesktopRect(this->pos()); } bool BaseWindow::getStayInScreenRect() const @@ -522,22 +522,17 @@ void BaseWindow::moveTo(QWidget *parent, QPoint point, bool offset) point.ry() += 16; } - this->moveIntoDesktopRect(parent, point); + this->moveIntoDesktopRect(point); } void BaseWindow::resizeEvent(QResizeEvent *) { // Queue up save because: Window resized -#ifdef CHATTERINO if (!flags_.has(DisableLayoutSave)) { getApp()->windows->queueSave(); } -#endif - - //this->moveIntoDesktopRect(this); - #ifdef USEWINSDK if (this->hasCustomWindowFrame() && !this->isResizeFixing_) { @@ -581,50 +576,55 @@ void BaseWindow::closeEvent(QCloseEvent *) void BaseWindow::showEvent(QShowEvent *) { - this->moveIntoDesktopRect(this, this->pos()); + this->moveIntoDesktopRect(this->pos()); if (this->frameless_) { QTimer::singleShot(30, this, [this] { - this->moveIntoDesktopRect(this, this->pos()); + this->moveIntoDesktopRect(this->pos()); }); } } -void BaseWindow::moveIntoDesktopRect(QWidget *parent, QPoint point) +void BaseWindow::moveIntoDesktopRect(QPoint point) { if (!this->stayInScreenRect_) + { return; + } // move the widget into the screen geometry if it's not already in there - QDesktopWidget *desktop = QApplication::desktop(); - QPoint globalCursorPos = QCursor::pos(); - - QRect s = desktop->availableGeometry(parent); + auto *screen = QApplication::screenAt(point); + if (screen == nullptr) + { + screen = QApplication::primaryScreen(); + } + const QRect bounds = screen->availableGeometry(); bool stickRight = false; bool stickBottom = false; - if (point.x() < s.left()) + if (point.x() < bounds.left()) { - point.setX(s.left()); + point.setX(bounds.left()); } - if (point.y() < s.top()) + if (point.y() < bounds.top()) { - point.setY(s.top()); + point.setY(bounds.top()); } - if (point.x() + this->width() > s.right()) + if (point.x() + this->width() > bounds.right()) { stickRight = true; - point.setX(s.right() - this->width()); + point.setX(bounds.right() - this->width()); } - if (point.y() + this->height() > s.bottom()) + if (point.y() + this->height() > bounds.bottom()) { stickBottom = true; - point.setY(s.bottom() - this->height()); + point.setY(bounds.bottom() - this->height()); } if (stickRight && stickBottom) { + const QPoint globalCursorPos = QCursor::pos(); point.setY(globalCursorPos.y() - this->height() - 16); } diff --git a/src/widgets/BaseWindow.hpp b/src/widgets/BaseWindow.hpp index 29a4e4743..3f99bc398 100644 --- a/src/widgets/BaseWindow.hpp +++ b/src/widgets/BaseWindow.hpp @@ -96,7 +96,7 @@ protected: private: void init(); - void moveIntoDesktopRect(QWidget *parent, QPoint point); + void moveIntoDesktopRect(QPoint point); void calcButtonsSizes(); void drawCustomWindowFrame(QPainter &painter); void onFocusLost(); diff --git a/src/widgets/dialogs/NotificationPopup.cpp b/src/widgets/dialogs/NotificationPopup.cpp index 9dfb46d10..5e8d7360b 100644 --- a/src/widgets/dialogs/NotificationPopup.cpp +++ b/src/widgets/dialogs/NotificationPopup.cpp @@ -5,7 +5,6 @@ #include "widgets/helper/ChannelView.hpp" #include -#include #include #include diff --git a/src/widgets/helper/Button.cpp b/src/widgets/helper/Button.cpp index 9f371a49b..4b86742ff 100644 --- a/src/widgets/helper/Button.cpp +++ b/src/widgets/helper/Button.cpp @@ -5,8 +5,8 @@ #include #include -#include #include +#include namespace chatterino { namespace { @@ -345,11 +345,16 @@ void Button::showMenu() return; auto point = [this] { - auto bounds = QApplication::desktop()->availableGeometry(this); - auto point = this->mapToGlobal( QPoint(this->width() - this->menu_->width(), this->height())); + auto *screen = QApplication::screenAt(point); + if (screen == nullptr) + { + screen = QApplication::primaryScreen(); + } + auto bounds = screen->availableGeometry(); + if (point.y() + this->menu_->height() > bounds.bottom()) { point.setY(point.y() - this->menu_->height() - this->height()); diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index b752c0370..0289c0f4c 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -28,7 +28,6 @@ #include "widgets/splits/SplitContainer.hpp" #include "widgets/TooltipWidget.hpp" -#include #include #include #include