Minor improvements.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-05-24 21:26:44 +08:00
parent e401db219d
commit a2fde746f5
1 changed files with 18 additions and 9 deletions

View File

@ -346,18 +346,27 @@ QSize FramelessQuickHelper::desktopAvailableSize() const {
void FramelessQuickHelper::moveWindowToDesktopCenter(const bool realCenter) { void FramelessQuickHelper::moveWindowToDesktopCenter(const bool realCenter) {
const auto win = window(); const auto win = window();
if (win) { if (win) {
if (realCenter) {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
const auto hWnd = reinterpret_cast<HWND>(win->winId()); const auto hWnd = reinterpret_cast<HWND>(win->winId());
if (hWnd) { if (hWnd) {
WinNativeEventFilter::moveWindowToDesktopCenter(hWnd); WinNativeEventFilter::moveWindowToDesktopCenter(hWnd);
} }
#else #else
FramelessHelper::moveWindowToDesktopCenter(win); FramelessHelper::moveWindowToDesktopCenter(win);
#endif #endif
if (!realCenter) { } else {
const auto dag = desktopAvailableGeometry(); const QSize windowSize = win->size();
win->setX(win->x() + dag.x()); const QSize screenSize = desktopAvailableSize();
win->setY(win->y() + dag.y()); const int newX = qRound(
static_cast<qreal>(screenSize.width() - windowSize.width()) /
2.0);
const int newY = qRound(
static_cast<qreal>(screenSize.height() - windowSize.height()) /
2.0);
const QRect screenGeometry = desktopAvailableGeometry();
win->setX(newX + screenGeometry.x());
win->setY(newY + screenGeometry.y());
} }
} }
} }