Add a few more functions to the quick helper.

Maybe useful.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-05-24 20:54:13 +08:00
parent 8ec1cfcf35
commit e401db219d
2 changed files with 44 additions and 2 deletions

View File

@ -28,6 +28,7 @@
#include "winnativeeventfilter.h"
#endif
#include <QQuickWindow>
#include <QScreen>
#ifdef Q_OS_WINDOWS
namespace {
@ -309,7 +310,40 @@ void FramelessQuickHelper::removeWindowFrame(const bool center) {
}
}
void FramelessQuickHelper::moveWindowToDesktopCenter() {
QSize FramelessQuickHelper::desktopSize() const {
const auto win = window();
if (win) {
const auto screen = win->screen();
if (screen) {
return screen->size();
}
}
return {};
}
QRect FramelessQuickHelper::desktopAvailableGeometry() const {
const auto win = window();
if (win) {
const auto screen = win->screen();
if (screen) {
return screen->availableGeometry();
}
}
return {};
}
QSize FramelessQuickHelper::desktopAvailableSize() const {
const auto win = window();
if (win) {
const auto screen = win->screen();
if (screen) {
return screen->availableSize();
}
}
return {};
}
void FramelessQuickHelper::moveWindowToDesktopCenter(const bool realCenter) {
const auto win = window();
if (win) {
#ifdef Q_OS_WINDOWS
@ -320,6 +354,11 @@ void FramelessQuickHelper::moveWindowToDesktopCenter() {
#else
FramelessHelper::moveWindowToDesktopCenter(win);
#endif
if (!realCenter) {
const auto dag = desktopAvailableGeometry();
win->setX(win->x() + dag.x());
win->setY(win->y() + dag.y());
}
}
}

View File

@ -91,7 +91,10 @@ public:
public Q_SLOTS:
void removeWindowFrame(const bool center = true);
void moveWindowToDesktopCenter();
void moveWindowToDesktopCenter(const bool realCenter = true);
QSize desktopSize() const;
QRect desktopAvailableGeometry() const;
QSize desktopAvailableSize() const;
void setIgnoreAreas(const QVector<QRect> &val);
void clearIgnoreAreas();