From eb276e717968cb71f4c1144b90f4b44e620b3c9b 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 22:09:39 +0800 Subject: [PATCH] update --- src/FluFramelessHelper.cpp | 29 ++++++++++++++++++++++++----- src/FluFramelessHelper.h | 3 ++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index 658ad79b..16f3bffb 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -184,7 +184,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * return false; }else if(uMsg == WM_NCRBUTTONDOWN){ if (wParam == HTCAPTION) { - _helper->showSystemMenu(); + _helper->showSystemMenu(QCursor::pos()); + } + }else if(uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN){ + const bool altPressed = ((wParam == VK_MENU) || (::GetKeyState(VK_MENU) < 0)); + const bool spacePressed = ((wParam == VK_SPACE) || (::GetKeyState(VK_SPACE) < 0)); + if (altPressed && spacePressed) { + auto pos = _helper->window->position(); + _helper->showSystemMenu(QPoint(pos.x(),pos.y()+_helper->getAppBarHeight())); } } return false; @@ -306,7 +313,7 @@ void FluFramelessHelper::componentComplete(){ if(!_appBar.isNull()){ _appBar.value()->setProperty("systemMoveEnable",false); } - window->setFlags((window->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint); + window->setFlags((window->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint); _nativeEvent =new FramelessEventFilter(this); qApp->installNativeEventFilter(_nativeEvent); HWND hwnd = reinterpret_cast(window->winId()); @@ -336,7 +343,9 @@ void FluFramelessHelper::componentComplete(){ #endif int w = _realWidth.read().toInt(); int h = _realHeight.read().toInt()+_appBarHeight.read().toInt(); - if(!resizeable()){ + if(resizeable()){ + window->setFlag(Qt::WindowMaximizeButtonHint); + }else{ window->setMaximumSize(QSize(w,h)); window->setMinimumSize(QSize(w,h)); } @@ -357,9 +366,8 @@ void FluFramelessHelper::_onScreenChanged(){ #endif } -void FluFramelessHelper::showSystemMenu(){ +void FluFramelessHelper::showSystemMenu(QPoint point){ #ifdef Q_OS_WIN - QPoint point = QCursor::pos(); HWND hwnd = reinterpret_cast(window->winId()); DWORD style = GetWindowLongPtr(hwnd,GWL_STYLE); SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_SYSMENU); @@ -439,6 +447,17 @@ QVariant FluFramelessHelper::getAppBar(){ return _appBar; } +int FluFramelessHelper::getAppBarHeight(){ + if(_appBar.isNull()){ + return 0; + } + QVariant var = _appBar.value()->property("height"); + if(var.isNull()){ + return 0; + } + return var.toInt(); +} + QObject* FluFramelessHelper::maximizeButton(){ if(_appBar.isNull()){ return nullptr; diff --git a/src/FluFramelessHelper.h b/src/FluFramelessHelper.h index 3b79baa7..dbe16480 100644 --- a/src/FluFramelessHelper.h +++ b/src/FluFramelessHelper.h @@ -49,10 +49,11 @@ public: int getMargins(); bool maximized(); bool fullScreen(); + int getAppBarHeight(); QVariant getAppBar(); QObject* maximizeButton(); void setOriginalPos(QVariant pos); - Q_INVOKABLE void showSystemMenu(); + Q_INVOKABLE void showSystemMenu(QPoint point); Q_SIGNAL void loadCompleted(); protected: bool eventFilter(QObject *obj, QEvent *event) override;