This commit is contained in:
朱子楚\zhuzi 2024-05-03 01:54:38 +08:00
parent 8015dcc2f1
commit 0eb4d9f346
3 changed files with 21 additions and 16 deletions

View File

@ -54,9 +54,9 @@ bool containsCursorToItem(QQuickItem *item) {
if (!item || !item->isVisible()) { if (!item || !item->isVisible()) {
return false; return false;
} }
auto point = QCursor::pos(); auto point = item->window()->mapFromGlobal(QCursor::pos());
auto rect = QRectF(item->mapToGlobal(QPoint(0, 0)), item->size()); auto rect = QRectF(item->mapToItem(item->window()->contentItem(), QPointF(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())) { if (rect.contains(point)) {
return true; return true;
} }
return false; return false;
@ -297,7 +297,9 @@ void FluFrameless::componentComplete() {
} }
} else if (uMsg == WM_NCRBUTTONDOWN) { } else if (uMsg == WM_NCRBUTTONDOWN) {
if (wParam == HTCAPTION) { 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) { } else if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN) {
const bool altPressed = ((wParam == VK_MENU) || (::GetKeyState(VK_MENU) < 0)); const bool altPressed = ((wParam == VK_MENU) || (::GetKeyState(VK_MENU) < 0));
@ -335,6 +337,15 @@ bool FluFrameless::_isFullScreen() {
void FluFrameless::_showSystemMenu(QPoint point) { void FluFrameless::_showSystemMenu(QPoint point) {
#ifdef Q_OS_WIN #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()); HWND hwnd = reinterpret_cast<HWND>(window()->winId());
DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE); DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_SYSMENU); ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_SYSMENU);
@ -353,8 +364,8 @@ void FluFrameless::_showSystemMenu(QPoint point) {
::EnableMenuItem(hMenu, SC_SIZE, MFS_DISABLED); ::EnableMenuItem(hMenu, SC_SIZE, MFS_DISABLED);
::EnableMenuItem(hMenu, SC_MAXIMIZE, 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()), const int result = ::TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), nativePos.x(),
qRound(point.y() * window()->devicePixelRatio()), 0, hwnd, nullptr); nativePos.y(), 0, hwnd, nullptr);
if (result != FALSE) { if (result != FALSE) {
::PostMessageW(hwnd, WM_SYSCOMMAND, result, 0); ::PostMessageW(hwnd, WM_SYSCOMMAND, result, 0);
} }

View File

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

View File

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