Remove Deprecated QDesktopWidget (#4287)

* fix: remove deprecated `QDesktopWidget`

* chore: add changelog entry
This commit is contained in:
nerix 2023-01-07 11:41:39 +01:00 committed by GitHub
parent e48945e370
commit 95b1f82620
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 30 deletions

View file

@ -27,6 +27,7 @@
- Dev: Removed unused include directives. (#4266, #4275) - Dev: Removed unused include directives. (#4266, #4275)
- Dev: Removed TooltipPreviewImage. (#4268) - Dev: Removed TooltipPreviewImage. (#4268)
- Dev: Removed unused operators in `Image` (#4267) - Dev: Removed unused operators in `Image` (#4267)
- Dev: Removed usage of deprecated `QDesktopWidget` (#4287)
## 2.4.0 ## 2.4.0

View file

@ -26,7 +26,6 @@
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <QDebug> #include <QDebug>
#include <QDesktopWidget>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>

View file

@ -12,9 +12,9 @@
#include "widgets/TooltipWidget.hpp" #include "widgets/TooltipWidget.hpp"
#include <QApplication> #include <QApplication>
#include <QDesktopWidget>
#include <QFont> #include <QFont>
#include <QIcon> #include <QIcon>
#include <QScreen>
#include <functional> #include <functional>
@ -244,7 +244,7 @@ void BaseWindow::setStayInScreenRect(bool value)
{ {
this->stayInScreenRect_ = value; this->stayInScreenRect_ = value;
this->moveIntoDesktopRect(this, this->pos()); this->moveIntoDesktopRect(this->pos());
} }
bool BaseWindow::getStayInScreenRect() const bool BaseWindow::getStayInScreenRect() const
@ -522,22 +522,17 @@ void BaseWindow::moveTo(QWidget *parent, QPoint point, bool offset)
point.ry() += 16; point.ry() += 16;
} }
this->moveIntoDesktopRect(parent, point); this->moveIntoDesktopRect(point);
} }
void BaseWindow::resizeEvent(QResizeEvent *) void BaseWindow::resizeEvent(QResizeEvent *)
{ {
// Queue up save because: Window resized // Queue up save because: Window resized
#ifdef CHATTERINO
if (!flags_.has(DisableLayoutSave)) if (!flags_.has(DisableLayoutSave))
{ {
getApp()->windows->queueSave(); getApp()->windows->queueSave();
} }
#endif
//this->moveIntoDesktopRect(this);
#ifdef USEWINSDK #ifdef USEWINSDK
if (this->hasCustomWindowFrame() && !this->isResizeFixing_) if (this->hasCustomWindowFrame() && !this->isResizeFixing_)
{ {
@ -581,50 +576,55 @@ void BaseWindow::closeEvent(QCloseEvent *)
void BaseWindow::showEvent(QShowEvent *) void BaseWindow::showEvent(QShowEvent *)
{ {
this->moveIntoDesktopRect(this, this->pos()); this->moveIntoDesktopRect(this->pos());
if (this->frameless_) if (this->frameless_)
{ {
QTimer::singleShot(30, this, [this] { 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_) if (!this->stayInScreenRect_)
{
return; return;
}
// move the widget into the screen geometry if it's not already in there // move the widget into the screen geometry if it's not already in there
QDesktopWidget *desktop = QApplication::desktop(); auto *screen = QApplication::screenAt(point);
QPoint globalCursorPos = QCursor::pos(); if (screen == nullptr)
{
QRect s = desktop->availableGeometry(parent); screen = QApplication::primaryScreen();
}
const QRect bounds = screen->availableGeometry();
bool stickRight = false; bool stickRight = false;
bool stickBottom = 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; 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; stickBottom = true;
point.setY(s.bottom() - this->height()); point.setY(bounds.bottom() - this->height());
} }
if (stickRight && stickBottom) if (stickRight && stickBottom)
{ {
const QPoint globalCursorPos = QCursor::pos();
point.setY(globalCursorPos.y() - this->height() - 16); point.setY(globalCursorPos.y() - this->height() - 16);
} }

View file

@ -96,7 +96,7 @@ protected:
private: private:
void init(); void init();
void moveIntoDesktopRect(QWidget *parent, QPoint point); void moveIntoDesktopRect(QPoint point);
void calcButtonsSizes(); void calcButtonsSizes();
void drawCustomWindowFrame(QPainter &painter); void drawCustomWindowFrame(QPainter &painter);
void onFocusLost(); void onFocusLost();

View file

@ -5,7 +5,6 @@
#include "widgets/helper/ChannelView.hpp" #include "widgets/helper/ChannelView.hpp"
#include <QApplication> #include <QApplication>
#include <QDesktopWidget>
#include <QScreen> #include <QScreen>
#include <QVBoxLayout> #include <QVBoxLayout>

View file

@ -5,8 +5,8 @@
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QDesktopWidget>
#include <QPainter> #include <QPainter>
#include <QScreen>
namespace chatterino { namespace chatterino {
namespace { namespace {
@ -345,11 +345,16 @@ void Button::showMenu()
return; return;
auto point = [this] { auto point = [this] {
auto bounds = QApplication::desktop()->availableGeometry(this);
auto point = this->mapToGlobal( auto point = this->mapToGlobal(
QPoint(this->width() - this->menu_->width(), this->height())); 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()) if (point.y() + this->menu_->height() > bounds.bottom())
{ {
point.setY(point.y() - this->menu_->height() - this->height()); point.setY(point.y() - this->menu_->height() - this->height());

View file

@ -28,7 +28,6 @@
#include "widgets/splits/SplitContainer.hpp" #include "widgets/splits/SplitContainer.hpp"
#include "widgets/TooltipWidget.hpp" #include "widgets/TooltipWidget.hpp"
#include <QDesktopWidget>
#include <QDrag> #include <QDrag>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QInputDialog> #include <QInputDialog>