From d43e6613883af5e6e7fd0380a7cd53a42b6e8729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A?= Date: Thu, 9 Mar 2023 01:18:46 +0800 Subject: [PATCH] update --- .DS_Store | Bin 0 -> 8196 bytes src/FluApp.cpp | 2 +- src/FluentUI.pro | 5 ++ src/FramelessView_mac.cpp | 109 +++++++++++++++++++++++++++++++++++++ src/FramelessView_unix.cpp | 2 +- src/controls/FluAppBar.qml | 4 +- src/controls/FluWindow.qml | 5 ++ src/macos_install.sh | 0 8 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 .DS_Store create mode 100644 src/FramelessView_mac.cpp mode change 100644 => 100755 src/macos_install.sh diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..63e907fdbc2b4f15c6a3fdffeabbec0fe832b5f3 GIT binary patch literal 8196 zcmeHMO-~a+7=8!PZUto#P{f!t_F@7-6oN6vxD-%{F(5^R0M_kxC>xfUW_Jq$A?aC9 z{s6su@@nEA@ZwQ##-E^9Px{VB`Pj-2A1ptz(maYKw0Dy%> zpxuhqFHDS!(qK*6BX|V)z`bI?i`cUpVvWNnU=%P47zK<1MuC4r0o=2NSx4;qYSh$5 z0i(cwsepJsWUvTyG}aW#M+a8&2!PmvZfV$-FaL-c;XrgW))b-#jVLOjq7r??Ao}b; z6dlJM9bZ$Z=s@Jmm`Be{^a+LNqX)^za3GFCQyT@00*wlYy}ubsz`>gg4xQgeab)0! zG)YSVg{R=cI#eJ4nuvarh;BU`4FeFt29yu8$b|%}4Q^xZDsmab@DL`ESAh_Cg7-YZ z>o|&s{3^~&AxvcWp2(1f8JK`k7>E0a1Gvi4VMbFq!AN0V53kL~D~usZM1M>~H)C}8 zOO0P0&{#(mH=~OFCFO0g68KR(IQWS)HMbl)p0ZL_tF@e8<(v7~jjK`44Hrdkmh+%k zZ@a}gpKccHt})JH*Jm`81iwTvWa*L5N_;cNtE?1BZe9&oX)9f@dv#wNGX%~rdC!W8qXhSFBI(d$P0N8O!LT( zea;q^B2;-Yrt6bzh2xAHsPI%p3`KJ^j1U_*^9ybmx~xodTg!o4q`?%+@i^w|^S;NK zy7G3J7Q53S6)Cf~z9|v2&b@l$l4{tHRSkfwQ?ALj)m3+CB(sb&n$9}Y%8|y6wGTho z_hAm!U>jb*OLz_M;5~eXukf9uh)ph%J~B*hl3V01c|c}}M^=eXLY1JYev8GI^?;EG zJNg!HK^e9Fmd$n|9|fS&CEst zqrh)hfV7O~$8$K1+L{~Z6KCxVmM2(*iMX0VNx@1U#}Vam9C7atLu_X-RB#-PHHGLw QGcN*C22&XY{-^>!0Z;`pr2qf` literal 0 HcmV?d00001 diff --git a/src/FluApp.cpp b/src/FluApp.cpp index 687575af..d72fbb50 100644 --- a/src/FluApp.cpp +++ b/src/FluApp.cpp @@ -59,7 +59,7 @@ void FluApp::navigate(const QString& route){ view->setSource((routes().value(route).toString())); if(isAppWindow){ QObject::connect(view->engine(), &QQmlEngine::quit, qApp, &QCoreApplication::quit); - QObject::connect(qApp, &QGuiApplication::aboutToQuit, qApp, [&view](){view->setSource({});}); +// QObject::connect(qApp, &QGuiApplication::aboutToQuit, qApp, [&view](){view->setSource({});}); }else{ view->closeDeleteLater(); } diff --git a/src/FluentUI.pro b/src/FluentUI.pro index 9476f93f..9b84e074 100644 --- a/src/FluentUI.pro +++ b/src/FluentUI.pro @@ -38,8 +38,13 @@ win32 { SOURCES += \ FramelessView_win.cpp } else { + macos { + SOURCES += \ + FramelessView_mac.cpp + }else{ SOURCES += \ FramelessView_unix.cpp + } } DEFINES += VERSION_IN=\\\"1.0.0\\\" diff --git a/src/FramelessView_mac.cpp b/src/FramelessView_mac.cpp new file mode 100644 index 00000000..c35d418f --- /dev/null +++ b/src/FramelessView_mac.cpp @@ -0,0 +1,109 @@ +#include "FramelessView.h" +#include +#include +#include +#include + +class FramelessViewPrivate +{ +public: + bool m_isMax = false; + bool m_isFull = false; + bool m_deleteLater = false; + QQuickItem *m_titleItem = nullptr; +}; +FramelessView::FramelessView(QWindow *parent) : Super(parent), d(new FramelessViewPrivate) +{ +// setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); + setResizeMode(SizeRootObjectToView); + setIsMax(windowState() == Qt::WindowMaximized); + setIsFull(windowState() == Qt::WindowFullScreen); + connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state) { + (void)state; + setIsMax(windowState() == Qt::WindowMaximized); + setIsFull(windowState() == Qt::WindowFullScreen); + }); +} +FramelessView::~FramelessView() +{ + delete d; +} +void FramelessView::showEvent(QShowEvent *e) +{ + Super::showEvent(e); +} +QRect FramelessView::calcCenterGeo(const QRect &screenGeo, const QSize &normalSize) +{ + int w = normalSize.width(); + int h = normalSize.height(); + int x = screenGeo.x() + (screenGeo.width() - w) / 2; + int y = screenGeo.y() + (screenGeo.height() - h) / 2; + if (screenGeo.width() < w) { + x = screenGeo.x(); + w = screenGeo.width(); + } + if (screenGeo.height() < h) { + y = screenGeo.y(); + h = screenGeo.height(); + } + + return { x, y, w, h }; +} +void FramelessView::moveToScreenCenter() +{ + auto geo = calcCenterGeo(screen()->availableGeometry(), size()); + if (minimumWidth() > geo.width() || minimumHeight() > geo.height()) { + setMinimumSize(geo.size()); + } + setGeometry(geo); + update(); +} +void FramelessView::closeDeleteLater(){ + d->m_deleteLater = true; +} + +bool FramelessView::isMax() const +{ + return d->m_isMax; +} +bool FramelessView::isFull() const +{ + return d->m_isFull; +} +QQuickItem *FramelessView::titleItem() const +{ + return d->m_titleItem; +} +void FramelessView::setIsMax(bool isMax) +{ + if (d->m_isMax == isMax) + return; + + d->m_isMax = isMax; + emit isMaxChanged(d->m_isMax); +} +void FramelessView::setIsFull(bool isFull) +{ + if(d->m_isFull == isFull) + return; + + d->m_isFull = isFull; + emit isFullChanged(d->m_isFull); +} +void FramelessView::setTitleItem(QQuickItem *item) +{ + d->m_titleItem = item; +} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool FramelessView::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) +#else +bool FramelessView::nativeEvent(const QByteArray &eventType, void *message, long *result) +#endif +{ + return Super::nativeEvent(eventType, message, result); +} + +void FramelessView::resizeEvent(QResizeEvent *e) +{ + Super::resizeEvent(e); +} diff --git a/src/FramelessView_unix.cpp b/src/FramelessView_unix.cpp index a129a10f..e0a22f6d 100644 --- a/src/FramelessView_unix.cpp +++ b/src/FramelessView_unix.cpp @@ -14,7 +14,7 @@ public: }; FramelessView::FramelessView(QWindow *parent) : Super(parent), d(new FramelessViewPrivate) { - setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); +// setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); setResizeMode(SizeRootObjectToView); setIsMax(windowState() == Qt::WindowMaximized); setIsFull(windowState() == Qt::WindowFullScreen); diff --git a/src/controls/FluAppBar.qml b/src/controls/FluAppBar.qml index 48b52c2d..f7616629 100644 --- a/src/controls/FluAppBar.qml +++ b/src/controls/FluAppBar.qml @@ -13,13 +13,15 @@ Rectangle{ return borerlessColor return Window.window.active ? borerlessColor : Qt.lighter(borerlessColor,1.1) } - height: 50 + property bool isMacos: Qt.platform.os === "osx" + height: isMacos ? 0 : 50 width: { if(parent==null) return 200 return parent.width } z: 65535 + clip: true property string title: "标题" property color textColor: FluTheme.isDark ? "#000000" : "#FFFFFF" property bool showDark: false diff --git a/src/controls/FluWindow.qml b/src/controls/FluWindow.qml index 74230024..69840e90 100644 --- a/src/controls/FluWindow.qml +++ b/src/controls/FluWindow.qml @@ -21,7 +21,12 @@ Item { property int minimumHeight property int maximumHeight + property bool isMacos: Qt.platform.os === "osx" + property int borderless:{ + if(isMacos){ + return 0 + } if(window === null) return 4 if(Window.window.visibility === Window.Maximized){ diff --git a/src/macos_install.sh b/src/macos_install.sh old mode 100644 new mode 100755