Compare commits

..

2 Commits

Author SHA1 Message Date
朱子楚\zhuzi
0eb4d9f346 update 2024-05-03 01:54:38 +08:00
朱子楚\zhuzi
8015dcc2f1 update 2024-05-02 23:52:30 +08:00
3 changed files with 48 additions and 20 deletions

View File

@ -54,9 +54,9 @@ bool containsCursorToItem(QQuickItem *item) {
if (!item || !item->isVisible()) {
return false;
}
auto point = QCursor::pos();
auto rect = QRectF(item->mapToGlobal(QPoint(0, 0)), item->size());
if (point.x() > rect.x() && point.x() < (rect.x() + rect.width()) && point.y() > rect.y() && point.y() < (rect.y() + rect.height())) {
auto point = item->window()->mapFromGlobal(QCursor::pos());
auto rect = QRectF(item->mapToItem(item->window()->contentItem(), QPointF(0, 0)), item->size());
if (rect.contains(point)) {
return true;
}
return false;
@ -105,14 +105,22 @@ void FluFrameless::componentComplete() {
HWND hwnd = reinterpret_cast<HWND>(window()->winId());
DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
if (_fixSize) {
#if (QT_VERSION == QT_VERSION_CHECK(6, 5, 3) || QT_VERSION == QT_VERSION_CHECK(6, 6, 0))
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME);;
#else
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);
#endif
for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) {
connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] {
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_FRAMECHANGED);
});
}
} else {
#if (QT_VERSION == QT_VERSION_CHECK(6, 5, 3) || QT_VERSION == QT_VERSION_CHECK(6, 6, 0))
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME);
#else
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CAPTION);
#endif
}
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
connect(window(), &QQuickWindow::screenChanged, this, [hwnd] {
@ -162,7 +170,6 @@ void FluFrameless::componentComplete() {
}
return false;
} else if (uMsg == WM_NCCALCSIZE) {
bool isMaximum = ::IsZoomed(hwnd);
const auto clientRect = ((wParam == FALSE) ? reinterpret_cast<LPRECT>(lParam) : &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]);
const LONG originalTop = clientRect->top;
const LONG originalLeft = clientRect->left;
@ -176,6 +183,13 @@ void FluFrameless::componentComplete() {
if (clientRect->left - originalLeft != 0) {
offsetXY = clientRect->left - originalLeft;
}
#if (QT_VERSION == QT_VERSION_CHECK(6, 5, 3) || QT_VERSION == QT_VERSION_CHECK(6, 6, 0))
clientRect->top = originalTop;
clientRect->bottom = originalBottom;
clientRect->left = originalLeft;
clientRect->right = originalRight;
#else
bool isMaximum = ::IsZoomed(hwnd);
if (!isMaximum) {
clientRect->top = originalTop;
clientRect->bottom = originalBottom;
@ -186,10 +200,8 @@ void FluFrameless::componentComplete() {
clientRect->bottom = originalBottom - offsetXY;
clientRect->left = originalLeft + offsetXY;
clientRect->right = originalRight - offsetXY;
#if (QT_VERSION == QT_VERSION_CHECK(6, 5, 3) || QT_VERSION == QT_VERSION_CHECK(6, 6, 0))
qWarning("This issue is Qt's own bug, which currently only exists in 6.5.3 and 6.6.0, and has been fixed in later versions");
#endif
}
#endif
_setMaximizeHovered(false);
*result = WVR_REDRAW;
return true;
@ -258,6 +270,17 @@ void FluFrameless::componentComplete() {
}
*result = TRUE;
return true;
} else if (uMsg == WM_GETMINMAXINFO) {
auto *minmaxInfo = reinterpret_cast<MINMAXINFO *>(lParam);
auto pixelRatio = window()->devicePixelRatio();
auto geometry = window()->screen()->availableGeometry();
RECT rect;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
minmaxInfo->ptMaxPosition.x = rect.left;
minmaxInfo->ptMaxPosition.y = rect.top;
minmaxInfo->ptMaxSize.x = qRound(geometry.width() * pixelRatio);
minmaxInfo->ptMaxSize.y = qRound(geometry.height() * pixelRatio);
return false;
} else if (_isWindows11OrGreater && (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN)) {
if (_hitMaximizeButton()) {
QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
@ -274,7 +297,9 @@ void FluFrameless::componentComplete() {
}
} else if (uMsg == WM_NCRBUTTONDOWN) {
if (wParam == HTCAPTION) {
_showSystemMenu(QCursor::pos());
auto pos = window()->position();
auto offset = window()->mapFromGlobal(QCursor::pos());
_showSystemMenu(QPoint(pos.x() + offset.x(), pos.y() + offset.y()));
}
} else if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN) {
const bool altPressed = ((wParam == VK_MENU) || (::GetKeyState(VK_MENU) < 0));
@ -312,6 +337,15 @@ bool FluFrameless::_isFullScreen() {
void FluFrameless::_showSystemMenu(QPoint point) {
#ifdef Q_OS_WIN
QScreen *screen = window()->screen();
if (!screen) {
screen = QGuiApplication::primaryScreen();
}
if (!screen) {
return;
}
const QPoint origin = screen->geometry().topLeft();
auto nativePos = QPointF(QPointF(point - origin) * window()->devicePixelRatio()).toPoint() + origin;
HWND hwnd = reinterpret_cast<HWND>(window()->winId());
DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_SYSMENU);
@ -330,8 +364,8 @@ void FluFrameless::_showSystemMenu(QPoint point) {
::EnableMenuItem(hMenu, SC_SIZE, MFS_DISABLED);
::EnableMenuItem(hMenu, SC_MAXIMIZE, MFS_DISABLED);
}
const int result = ::TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), qRound(point.x() * window()->devicePixelRatio()),
qRound(point.y() * window()->devicePixelRatio()), 0, hwnd, nullptr);
const int result = ::TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), nativePos.x(),
nativePos.y(), 0, hwnd, nullptr);
if (result != FALSE) {
::PostMessageW(hwnd, WM_SYSCOMMAND, result, 0);
}

View File

@ -38,7 +38,6 @@ Item {
}
Row {
spacing: 5
FluToggleButton {
property int pageNumber: 1
visible: control.pageCount > 0
@ -98,7 +97,6 @@ Item {
sourceComponent: footer
}
}
function calcNewPage(page) {
if (!page)
return
@ -108,5 +106,4 @@ Item {
control.pageCurrent = page_num
control.requestPage(page_num, control.__itemPerPage)
}
}

View File

@ -1,7 +1,7 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import FluentUI 1.0
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import FluentUI
Item {
signal requestPage(int page, int count)
@ -37,7 +37,6 @@ Item {
}
Row {
spacing: 5
FluToggleButton {
property int pageNumber: 1
visible: control.pageCount > 0
@ -97,7 +96,6 @@ Item {
sourceComponent: footer
}
}
function calcNewPage(page) {
if (!page)
return
@ -107,5 +105,4 @@ Item {
control.pageCurrent = page_num
control.requestPage(page_num, control.__itemPerPage)
}
}