This commit is contained in:
朱子楚\zhuzi 2024-03-11 12:36:20 +08:00
parent d79a7df389
commit 38a277801d
6 changed files with 44 additions and 67 deletions

View File

@ -72,10 +72,8 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
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;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const LONG originalRight = clientRect->right;
const LONG originalBottom = clientRect->bottom;
#endif
const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) {
*result = hitTestResult;
@ -85,23 +83,19 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
bool isMaximum = ::IsZoomed(hwnd);
offsetXY = QPoint(abs(clientRect->left - originalLeft),abs(clientRect->top - originalTop));
if(isMaximum || _helper->fullScreen()){
_helper->setOriginalPos(QPoint(originalLeft,originalTop));
offsetSize = 0;
}else{
_helper->setOriginalPos({});
offsetSize = 1;
}
if(!isCompositionEnabled()){
offsetSize = 0;
}
clientRect->top = originalTop+offsetSize;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
if(!isMaximum){
clientRect->bottom = originalBottom-offsetSize;
clientRect->left = originalLeft+offsetSize;
clientRect->right = originalRight-offsetSize;
if (!isMaximum || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) {
clientRect->top = originalTop + offsetSize;
clientRect->bottom = originalBottom - offsetSize;
clientRect->left = originalLeft + offsetSize;
clientRect->right = originalRight - offsetSize;
}
#endif
*result = WVR_REDRAW;
return true;
}if(uMsg == WM_NCHITTEST){
@ -172,13 +166,11 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
*result = ::DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1);
return true;
}else if(uMsg == WM_GETMINMAXINFO){
#if QT_VERSION < QT_VERSION_CHECK(6,2,4)
MINMAXINFO* minmaxInfo = reinterpret_cast<MINMAXINFO *>(lParam);
auto pixelRatio = _helper->window->devicePixelRatio();
auto geometry = _helper->window->screen()->availableGeometry();
minmaxInfo->ptMaxSize.x = geometry.width()*pixelRatio + offsetXY.x()*2;
minmaxInfo->ptMaxSize.y = geometry.height()*pixelRatio + offsetXY.y()*2;
#endif
minmaxInfo->ptMaxSize.x = geometry.width()*pixelRatio + offsetXY.x() * 2;
minmaxInfo->ptMaxSize.y = geometry.height()*pixelRatio + offsetXY.y() * 2;
return false;
}else if(uMsg == WM_NCRBUTTONDOWN){
if (wParam == HTCAPTION) {
@ -302,7 +294,6 @@ void FluFramelessHelper::componentComplete(){
_stayTop = QQmlProperty(window,"stayTop");
_screen = QQmlProperty(window,"screen");
_fixSize = QQmlProperty(window,"fixSize");
_originalPos = QQmlProperty(window,"_originalPos");
_realHeight = QQmlProperty(window,"_realHeight");
_realWidth = QQmlProperty(window,"_realWidth");
_appBarHeight = QQmlProperty(window,"_appBarHeight");
@ -311,7 +302,7 @@ void FluFramelessHelper::componentComplete(){
if(!_appBar.isNull()){
_appBar.value<QObject*>()->setProperty("systemMoveEnable",false);
}
window->setFlags((window->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
window->setFlags((window->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::FramelessWindowHint);
if(resizeable()){
window->setFlag(Qt::WindowMaximizeButtonHint);
}
@ -324,9 +315,6 @@ void FluFramelessHelper::componentComplete(){
}else{
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME);
}
LONG exstyle = ::GetWindowLong(hwnd, GWL_EXSTYLE);
exstyle = exstyle | 0x02000000;
::SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle);
#else
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
window->installEventFilter(this);
@ -382,6 +370,13 @@ void FluFramelessHelper::showSystemMenu(QPoint point){
#endif
}
void FluFramelessHelper::showMaximized(){
#ifdef Q_OS_WIN
HWND hwnd = reinterpret_cast<HWND>(window->winId());
::ShowWindow(hwnd,3);
#endif
}
void FluFramelessHelper::_onStayTopChange(){
bool isStayTop = _stayTop.read().toBool();
#ifdef Q_OS_WIN
@ -457,10 +452,6 @@ QObject* FluFramelessHelper::maximizeButton(){
return var.value<QObject*>();
}
void FluFramelessHelper::setOriginalPos(QVariant pos){
_originalPos.write(pos);
}
bool FluFramelessHelper::resizeable(){
return !_fixSize.read().toBool();
}

View File

@ -54,6 +54,7 @@ public:
QObject* maximizeButton();
void setOriginalPos(QVariant pos);
Q_INVOKABLE void showSystemMenu(QPoint point);
Q_INVOKABLE void showMaximized();
Q_SIGNAL void loadCompleted();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
@ -67,7 +68,6 @@ private:
FramelessEventFilter* _nativeEvent = nullptr;
QQmlProperty _stayTop;
QQmlProperty _screen;
QQmlProperty _originalPos;
QQmlProperty _fixSize;
QQmlProperty _realHeight;
QQmlProperty _realWidth;

View File

@ -37,19 +37,19 @@ Rectangle{
property var maxClickListener : function(){
if(FluTools.isMacos()){
if (d.win.visibility === Window.FullScreen)
d.win.visibility = Window.Windowed
d.win.showNormal()
else
d.win.visibility = Window.FullScreen
d.win.showFullScreen()
}else{
if (d.win.visibility === Window.Maximized)
d.win.visibility = Window.Windowed
d.win.showNormal()
else
d.win.visibility = Window.Maximized
d.win.showMaximized()
d.hoverMaxBtn = false
}
}
property var minClickListener: function(){
d.win.visibility = Window.Minimized
d.win.showMinimized()
}
property var closeClickListener : function(){
d.win.close()

View File

@ -58,8 +58,6 @@ Window {
signal showSystemMenu
signal initArgument(var argument)
signal firstVisible()
property point _offsetXY : Qt.point(0,0)
property var _originalPos
property int _realHeight
property int _realWidth
property int _appBarHeight: appBar.height
@ -91,19 +89,6 @@ Window {
Component.onDestruction: {
lifecycle.onDestruction()
}
on_OriginalPosChanged: {
if(_originalPos){
var dx = (_originalPos.x - screen.virtualX)/screen.devicePixelRatio
var dy = (_originalPos.y - screen.virtualY)/screen.devicePixelRatio
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()
@ -223,7 +208,6 @@ Window {
id:layout_container
anchors{
fill:parent
topMargin: _offsetXY.y
}
onWidthChanged: {
window.appBar.width = width
@ -337,4 +321,13 @@ Window {
function layoutContent(){
return layout_content
}
function showMaximized(){
if(FluTools.isWin()){
if(loader_frameless_helper.item){
loader_frameless_helper.item.showMaximized()
}
}else{
window.visibility = Qt.WindowMaximized
}
}
}

View File

@ -37,19 +37,19 @@ Rectangle{
property var maxClickListener : function(){
if(FluTools.isMacos()){
if (d.win.visibility === Window.FullScreen)
d.win.visibility = Window.Windowed
d.win.showNormal()
else
d.win.visibility = Window.FullScreen
d.win.showFullScreen()
}else{
if (d.win.visibility === Window.Maximized)
d.win.visibility = Window.Windowed
d.win.showNormal()
else
d.win.visibility = Window.Maximized
d.win.showMaximized()
d.hoverMaxBtn = false
}
}
property var minClickListener: function(){
d.win.visibility = Window.Minimized
d.win.showMinimized()
}
property var closeClickListener : function(){
d.win.close()

View File

@ -57,8 +57,6 @@ Window {
signal showSystemMenu
signal initArgument(var argument)
signal firstVisible()
property point _offsetXY : Qt.point(0,0)
property var _originalPos
property int _realHeight
property int _realWidth
property int _appBarHeight: appBar.height
@ -90,19 +88,6 @@ Window {
Component.onDestruction: {
lifecycle.onDestruction()
}
on_OriginalPosChanged: {
if(_originalPos){
var dx = (_originalPos.x - screen.virtualX)/screen.devicePixelRatio
var dy = (_originalPos.y - screen.virtualY)/screen.devicePixelRatio
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()
@ -222,7 +207,6 @@ Window {
id:layout_container
anchors{
fill:parent
topMargin: _offsetXY.y
}
onWidthChanged: {
window.appBar.width = width
@ -336,4 +320,13 @@ Window {
function layoutContent(){
return layout_content
}
function showMaximized(){
if(FluTools.isWin()){
if(loader_frameless_helper.item){
loader_frameless_helper.item.showMaximized()
}
}else{
window.visibility = Qt.WindowMaximized
}
}
}