mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-26 21:37:04 +08:00
update
This commit is contained in:
parent
0b0fbe1e64
commit
8253fb611f
@ -1,7 +1,6 @@
|
||||
#include "FluFramelessHelper.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include "FluTools.h"
|
||||
#ifdef Q_OS_WIN
|
||||
#pragma comment (lib,"user32.lib")
|
||||
#pragma comment (lib,"dwmapi.lib")
|
||||
@ -14,6 +13,28 @@ static inline QByteArray qtNativeEventType()
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline bool isWindows11OrGreater() {
|
||||
DWORD dwVersion = 0;
|
||||
DWORD dwBuild = 0;
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996)
|
||||
dwVersion = GetVersion();
|
||||
if (dwVersion < 0x80000000)
|
||||
dwBuild = (DWORD)(HIWORD(dwVersion));
|
||||
#pragma warning(pop)
|
||||
return dwBuild < 22000;
|
||||
}
|
||||
|
||||
|
||||
static inline bool isTaskbarAutoHide() {
|
||||
APPBARDATA appBarData;
|
||||
memset(&appBarData, 0, sizeof(appBarData));
|
||||
appBarData.cbSize = sizeof(appBarData);
|
||||
appBarData.hWnd = FindWindowW(L"Shell_TrayWnd", NULL);
|
||||
LPARAM lParam = SHAppBarMessage(ABM_GETSTATE, &appBarData);
|
||||
return lParam & ABS_AUTOHIDE;
|
||||
}
|
||||
|
||||
static inline bool isCompositionEnabled(){
|
||||
typedef HRESULT (WINAPI* DwmIsCompositionEnabledPtr)(BOOL *pfEnabled);
|
||||
HMODULE module = LoadLibraryW(L"dwmapi.dll");
|
||||
@ -89,6 +110,20 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
||||
}
|
||||
return false;
|
||||
}else if(uMsg == WM_NCCALCSIZE){
|
||||
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
|
||||
if(IsZoomed(hwnd)){
|
||||
sz->rgrc[0].left += 8;
|
||||
sz->rgrc[0].top += 8;
|
||||
sz->rgrc[0].right -= 8;
|
||||
sz->rgrc[0].bottom -= isTaskbarAutoHide() ? 9 : 8;
|
||||
}else{
|
||||
sz->rgrc[0].top += isWindows11OrGreater() ? 0 : 1;
|
||||
if(isCompositionEnabled()){
|
||||
sz->rgrc[0].right -= 8;
|
||||
sz->rgrc[0].bottom -= 8;
|
||||
sz->rgrc[0].left -= -8;
|
||||
}
|
||||
}
|
||||
*result = WVR_REDRAW;
|
||||
return true;
|
||||
}else if(uMsg == WM_NCPAINT){
|
||||
@ -104,7 +139,7 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
||||
}
|
||||
return false;
|
||||
}else if(uMsg == WM_NCHITTEST){
|
||||
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
|
||||
if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
|
||||
if (*result == HTNOWHERE) {
|
||||
*result = HTZOOM;
|
||||
}
|
||||
@ -112,14 +147,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
||||
}
|
||||
return false;
|
||||
}else if(uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN){
|
||||
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
|
||||
if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
|
||||
QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}else if(uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP){
|
||||
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
|
||||
if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
|
||||
QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
|
||||
}
|
||||
@ -234,7 +269,9 @@ void FluFramelessHelper::componentComplete(){
|
||||
}
|
||||
if(!window.isNull()){
|
||||
#ifdef Q_OS_WIN
|
||||
window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
|
||||
if(!isCompositionEnabled()){
|
||||
window->setFlag(Qt::FramelessWindowHint,true);
|
||||
}
|
||||
_nativeEvent =new FramelessEventFilter(this);
|
||||
qApp->installNativeEventFilter(_nativeEvent);
|
||||
HWND hwnd = reinterpret_cast<HWND>(window->winId());
|
||||
@ -244,7 +281,6 @@ void FluFramelessHelper::componentComplete(){
|
||||
}else{
|
||||
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);
|
||||
}
|
||||
showShadow(hwnd);
|
||||
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
||||
#else
|
||||
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
|
||||
|
@ -200,14 +200,15 @@ bool FluTools::isWindows11OrGreater(){
|
||||
static QVariant var;
|
||||
if(var.isNull()){
|
||||
#if defined(Q_OS_WIN)
|
||||
QSettings regKey {QString::fromUtf8("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), QSettings::NativeFormat};
|
||||
if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) {
|
||||
auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt();
|
||||
if(buildNumber>=22000){
|
||||
var = QVariant::fromValue(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
DWORD dwVersion = 0;
|
||||
DWORD dwBuild = 0;
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996)
|
||||
dwVersion = GetVersion();
|
||||
if (dwVersion < 0x80000000)
|
||||
dwBuild = (DWORD)(HIWORD(dwVersion));
|
||||
#pragma warning(pop)
|
||||
return dwBuild < 22000;
|
||||
#endif
|
||||
var = QVariant::fromValue(false);
|
||||
return false;
|
||||
|
@ -53,7 +53,6 @@ Window {
|
||||
signal showSystemMenu
|
||||
signal initArgument(var argument)
|
||||
signal firstVisible()
|
||||
property point _offsetXY : Qt.point(0,0)
|
||||
id:window
|
||||
color:"transparent"
|
||||
Component.onCompleted: {
|
||||
@ -73,19 +72,6 @@ Window {
|
||||
Component.onDestruction: {
|
||||
lifecycle.onDestruction()
|
||||
}
|
||||
onVisibilityChanged: {
|
||||
if(visibility === Window.Maximized || visibility === Window.FullScreen){
|
||||
var dx = window.x-Screen.virtualX
|
||||
var dy = window.y-Screen.virtualY
|
||||
if(dx<0 && dy<0){
|
||||
_offsetXY = Qt.point(Math.abs(dx+1),Math.abs(dy+1))
|
||||
}else{
|
||||
_offsetXY = Qt.point(0,0)
|
||||
}
|
||||
}else{
|
||||
_offsetXY = Qt.point(0,0)
|
||||
}
|
||||
}
|
||||
onShowSystemMenu: {
|
||||
if(loader_frameless_helper.item){
|
||||
loader_frameless_helper.item.showSystemMenu()
|
||||
@ -191,10 +177,6 @@ Window {
|
||||
id:layout_container
|
||||
anchors{
|
||||
fill:parent
|
||||
leftMargin: _offsetXY.x
|
||||
rightMargin: _offsetXY.x
|
||||
topMargin: _offsetXY.y
|
||||
bottomMargin: _offsetXY.y
|
||||
}
|
||||
onWidthChanged: {
|
||||
window.appBar.width = width
|
||||
@ -247,7 +229,7 @@ Window {
|
||||
border.width: window.resizeBorderWidth
|
||||
border.color: window.resizeBorderColor
|
||||
visible: {
|
||||
if(window.useSystemAppBar){
|
||||
if(window.useSystemAppBar || FluTools.isWin()){
|
||||
return false
|
||||
}
|
||||
if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){
|
||||
|
@ -52,7 +52,6 @@ Window {
|
||||
signal showSystemMenu
|
||||
signal initArgument(var argument)
|
||||
signal firstVisible()
|
||||
property point _offsetXY : Qt.point(0,0)
|
||||
id:window
|
||||
color:"transparent"
|
||||
Component.onCompleted: {
|
||||
@ -72,19 +71,6 @@ Window {
|
||||
Component.onDestruction: {
|
||||
lifecycle.onDestruction()
|
||||
}
|
||||
onVisibilityChanged: {
|
||||
if(visibility === Window.Maximized || visibility === Window.FullScreen){
|
||||
var dx = window.x-Screen.virtualX
|
||||
var dy = window.y-Screen.virtualY
|
||||
if(dx<0 && dy<0){
|
||||
_offsetXY = Qt.point(Math.abs(dx+1),Math.abs(dy+1))
|
||||
}else{
|
||||
_offsetXY = Qt.point(0,0)
|
||||
}
|
||||
}else{
|
||||
_offsetXY = Qt.point(0,0)
|
||||
}
|
||||
}
|
||||
onShowSystemMenu: {
|
||||
if(loader_frameless_helper.item){
|
||||
loader_frameless_helper.item.showSystemMenu()
|
||||
@ -190,10 +176,6 @@ Window {
|
||||
id:layout_container
|
||||
anchors{
|
||||
fill:parent
|
||||
leftMargin: _offsetXY.x
|
||||
rightMargin: _offsetXY.x
|
||||
topMargin: _offsetXY.y
|
||||
bottomMargin: _offsetXY.y
|
||||
}
|
||||
onWidthChanged: {
|
||||
window.appBar.width = width
|
||||
@ -246,7 +228,7 @@ Window {
|
||||
border.width: window.resizeBorderWidth
|
||||
border.color: window.resizeBorderColor
|
||||
visible: {
|
||||
if(window.useSystemAppBar){
|
||||
if(window.useSystemAppBar || FluTools.isWin()){
|
||||
return false
|
||||
}
|
||||
if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){
|
||||
|
Loading…
Reference in New Issue
Block a user