From 94c3ec83b3b69c82b8c8e9049767c3dfa89ea56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Tue, 27 Feb 2024 16:27:48 +0800 Subject: [PATCH] fix bug #436 --- src/FluFramelessHelper.cpp | 34 ++++++++----------- .../imports/FluentUI/Controls/FluAppBar.qml | 26 ++++++++------ .../imports/FluentUI/Controls/FluAppBar.qml | 26 ++++++++------ 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index c5acdcea..658ad79b 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -112,16 +112,18 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * return true; } *result = 0; - short x = LOWORD(msg->lParam); - short y = HIWORD(msg->lParam); + POINT nativeGlobalPos{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; + POINT nativeLocalPos = nativeGlobalPos; + ::ScreenToClient(hwnd, &nativeLocalPos); + RECT clientRect{0, 0, 0, 0}; + ::GetClientRect(hwnd, &clientRect); + auto clientWidth = clientRect.right-clientRect.left; + auto clientHeight = clientRect.bottom-clientRect.top; int margins = _helper->getMargins(); - QPointer win = _helper->window; - qreal dp = _helper->window->devicePixelRatio(); - QPoint pos = win->mapFromGlobal(QPoint(x/dp, y/dp)); - bool left = pos.x() < margins; - bool right = pos.x() > win->width() - margins; - bool top = pos.y() < margins; - bool bottom = pos.y() > win->height() - margins; + bool left = nativeLocalPos.x < margins; + bool right = nativeLocalPos.x > clientWidth - margins; + bool top = nativeLocalPos.y < margins; + bool bottom = nativeLocalPos.y > clientHeight - margins; *result = 0; if (_helper->resizeable() && !_helper->fullScreen() && !_helper->maximized()) { if (left && top) { @@ -146,17 +148,9 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * return true; } QVariant appBar = _helper->getAppBar(); - if(!appBar.isNull()){ - auto item = appBar.value(); - if(item->contains(pos)){ - QPoint appBarTopLeft = item->mapToItem(_helper->window->contentItem(),QPoint(0, 0)).toPoint(); - QRect rcAppBar = QRect(appBarTopLeft, QSize(item->width(), item->height())); - if (rcAppBar.contains(pos) && _helper->hoverAppBar()) - { - *result = HTCAPTION; - return true; - } - } + if(!appBar.isNull()&& _helper->hoverAppBar()){ + *result = HTCAPTION; + return true; } *result = HTCLIENT; return true; diff --git a/src/Qt5/imports/FluentUI/Controls/FluAppBar.qml b/src/Qt5/imports/FluentUI/Controls/FluAppBar.qml index 5332f367..1930e6d7 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluAppBar.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluAppBar.qml @@ -94,6 +94,14 @@ Rectangle{ } property bool isRestore: win && Window.Maximized === win.visibility property bool resizable: win && !(win.height === win.maximumHeight && win.height === win.minimumHeight && win.width === win.maximumWidth && win.width === win.minimumWidth) + function containsPointToItem(point,item){ + var pos = item.mapToGlobal(0,0) + var rect = Qt.rect(pos.x,pos.y,item.width,item.height) + if(point.x>rect.x && point.x<(rect.x+rect.width) && point.y>rect.y && point.y<(rect.y+rect.height)){ + return true + } + return false + } } MouseArea{ id:mouse_app_bar @@ -283,30 +291,28 @@ Rectangle{ } function _maximizeButtonHover(){ var hover = false - var pos = btn_maximize.mapToGlobal(0,0) if(btn_maximize.visible){ - var rect = Qt.rect(pos.x,pos.y,btn_maximize.width,btn_maximize.height) - pos = FluTools.cursorPos() - if(pos.x>rect.x && pos.x<(rect.x+rect.width) && pos.y>rect.y && pos.y<(rect.y+rect.height)){ - hover = true; + if(d.containsPointToItem(FluTools.cursorPos(),btn_maximize)){ + hover = true } } d.hoverMaxBtn = hover return hover; } function _appBarHover(){ + var cursorPos = FluTools.cursorPos() for(var i =0 ;i< d.hitTestList.length; i++){ var item = d.hitTestList[i] - var pos = item.mapToGlobal(0,0) if(item.visible){ - var rect = Qt.rect(pos.x,pos.y,item.width,item.height) - pos = FluTools.cursorPos() - if(pos.x>rect.x && pos.x<(rect.x+rect.width) && pos.y>rect.y && pos.y<(rect.y+rect.height)){ + if(d.containsPointToItem(cursorPos,item)){ return false } } } - return true + if(d.containsPointToItem(cursorPos,control)){ + return true + } + return false } function setHitTestVisible(id){ d.hitTestList.push(id) diff --git a/src/Qt6/imports/FluentUI/Controls/FluAppBar.qml b/src/Qt6/imports/FluentUI/Controls/FluAppBar.qml index 0e6f5963..db0a42af 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluAppBar.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluAppBar.qml @@ -94,6 +94,14 @@ Rectangle{ } property bool isRestore: win && Window.Maximized === win.visibility property bool resizable: win && !(win.height === win.maximumHeight && win.height === win.minimumHeight && win.width === win.maximumWidth && win.width === win.minimumWidth) + function containsPointToItem(point,item){ + var pos = item.mapToGlobal(0,0) + var rect = Qt.rect(pos.x,pos.y,item.width,item.height) + if(point.x>rect.x && point.x<(rect.x+rect.width) && point.y>rect.y && point.y<(rect.y+rect.height)){ + return true + } + return false + } } MouseArea{ id:mouse_app_bar @@ -283,30 +291,28 @@ Rectangle{ } function _maximizeButtonHover(){ var hover = false - var pos = btn_maximize.mapToGlobal(0,0) if(btn_maximize.visible){ - var rect = Qt.rect(pos.x,pos.y,btn_maximize.width,btn_maximize.height) - pos = FluTools.cursorPos() - if(pos.x>rect.x && pos.x<(rect.x+rect.width) && pos.y>rect.y && pos.y<(rect.y+rect.height)){ - hover = true; + if(d.containsPointToItem(FluTools.cursorPos(),btn_maximize)){ + hover = true } } d.hoverMaxBtn = hover return hover; } function _appBarHover(){ + var cursorPos = FluTools.cursorPos() for(var i =0 ;i< d.hitTestList.length; i++){ var item = d.hitTestList[i] - var pos = item.mapToGlobal(0,0) if(item.visible){ - var rect = Qt.rect(pos.x,pos.y,item.width,item.height) - pos = FluTools.cursorPos() - if(pos.x>rect.x && pos.x<(rect.x+rect.width) && pos.y>rect.y && pos.y<(rect.y+rect.height)){ + if(d.containsPointToItem(cursorPos,item)){ return false } } } - return true + if(d.containsPointToItem(cursorPos,control)){ + return true + } + return false } function setHitTestVisible(id){ d.hitTestList.push(id)