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) {
const auto win = window();
if (win) {
if (realCenter) {
#ifdef Q_OS_WINDOWS
const auto hWnd = reinterpret_cast<HWND>(win->winId());
if (hWnd) {
WinNativeEventFilter::moveWindowToDesktopCenter(hWnd);
}
const auto hWnd = reinterpret_cast<HWND>(win->winId());
if (hWnd) {
WinNativeEventFilter::moveWindowToDesktopCenter(hWnd);
}
#else
FramelessHelper::moveWindowToDesktopCenter(win);
FramelessHelper::moveWindowToDesktopCenter(win);
#endif
if (!realCenter) {
const auto dag = desktopAvailableGeometry();
win->setX(win->x() + dag.x());
win->setY(win->y() + dag.y());
} else {
const QSize windowSize = win->size();
const QSize screenSize = desktopAvailableSize();
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());
}
}
}