mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-01-23 04:14:35 +08:00
update
This commit is contained in:
parent
42f0987e73
commit
6221eb4178
@ -9,7 +9,7 @@ FluWindow {
|
|||||||
id:window
|
id:window
|
||||||
title:"关于"
|
title:"关于"
|
||||||
width: 600
|
width: 600
|
||||||
height: 600
|
height: 580
|
||||||
fixSize: true
|
fixSize: true
|
||||||
launchMode: FluWindowType.SingleTask
|
launchMode: FluWindowType.SingleTask
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ FluWindow {
|
|||||||
id:window
|
id:window
|
||||||
title:"关于"
|
title:"关于"
|
||||||
width: 600
|
width: 600
|
||||||
height: 600
|
height: 580
|
||||||
fixSize: true
|
fixSize: true
|
||||||
launchMode: FluWindowType.SingleTask
|
launchMode: FluWindowType.SingleTask
|
||||||
|
|
||||||
|
@ -23,6 +23,24 @@ static inline bool isTaskbarAutoHide() {
|
|||||||
return lParam & ABS_AUTOHIDE;
|
return lParam & ABS_AUTOHIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline QColor getAccentColor(){
|
||||||
|
typedef HRESULT (WINAPI* DwmGetColorizationColorPtr)(DWORD* pcrColorization,BOOL* pfOpaqueBlend);
|
||||||
|
HMODULE module = LoadLibraryW(L"dwmapi.dll");
|
||||||
|
if (module)
|
||||||
|
{
|
||||||
|
DwmGetColorizationColorPtr dwm_get_colorization_color;
|
||||||
|
dwm_get_colorization_color= reinterpret_cast<DwmGetColorizationColorPtr>(GetProcAddress(module, "DwmGetColorizationColor"));
|
||||||
|
DWORD color = 0;
|
||||||
|
BOOL bOpaque = FALSE;
|
||||||
|
if (dwm_get_colorization_color)
|
||||||
|
{
|
||||||
|
dwm_get_colorization_color(&color,&bOpaque);
|
||||||
|
}
|
||||||
|
return QColor(color);
|
||||||
|
}
|
||||||
|
return QColor();
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool isCompositionEnabled(){
|
static inline bool isCompositionEnabled(){
|
||||||
typedef HRESULT (WINAPI* DwmIsCompositionEnabledPtr)(BOOL *pfEnabled);
|
typedef HRESULT (WINAPI* DwmIsCompositionEnabledPtr)(BOOL *pfEnabled);
|
||||||
HMODULE module = LoadLibraryW(L"dwmapi.dll");
|
HMODULE module = LoadLibraryW(L"dwmapi.dll");
|
||||||
@ -41,22 +59,17 @@ static inline bool isCompositionEnabled(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void showShadow(HWND hwnd){
|
static inline void showShadow(HWND hwnd){
|
||||||
if(isCompositionEnabled()){
|
const MARGINS shadow = { 0, 0, 1, 0 };
|
||||||
const MARGINS shadow = { 0, 0, 1, 0 };
|
typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset);
|
||||||
typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset);
|
HMODULE module = LoadLibraryW(L"dwmapi.dll");
|
||||||
HMODULE module = LoadLibraryW(L"dwmapi.dll");
|
if (module)
|
||||||
if (module)
|
{
|
||||||
|
DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_;
|
||||||
|
dwm_extendframe_into_client_area_= reinterpret_cast<DwmExtendFrameIntoClientAreaPtr>(GetProcAddress(module, "DwmExtendFrameIntoClientArea"));
|
||||||
|
if (dwm_extendframe_into_client_area_)
|
||||||
{
|
{
|
||||||
DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_;
|
dwm_extendframe_into_client_area_(hwnd, &shadow);
|
||||||
dwm_extendframe_into_client_area_= reinterpret_cast<DwmExtendFrameIntoClientAreaPtr>(GetProcAddress(module, "DwmExtendFrameIntoClientArea"));
|
|
||||||
if (dwm_extendframe_into_client_area_)
|
|
||||||
{
|
|
||||||
dwm_extendframe_into_client_area_(hwnd, &shadow);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
ULONG_PTR cNewStyle = GetClassLongPtr(hwnd, GCL_STYLE) | CS_DROPSHADOW;
|
|
||||||
SetClassLongPtr(hwnd, GCL_STYLE, cNewStyle);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,25 +121,16 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
|||||||
}
|
}
|
||||||
if(IsZoomed(hwnd)){
|
if(IsZoomed(hwnd)){
|
||||||
_helper->setOriginalPos(QPoint(originalLeft,originalTop));
|
_helper->setOriginalPos(QPoint(originalLeft,originalTop));
|
||||||
|
if(isTaskbarAutoHide()){
|
||||||
|
clientRect->bottom -= 1;
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
_helper->setOriginalPos({});
|
_helper->setOriginalPos({});
|
||||||
}
|
}
|
||||||
clientRect->top = originalTop;
|
clientRect->top = originalTop;
|
||||||
*result = WVR_REDRAW;
|
*result = WVR_REDRAW;
|
||||||
return true;
|
return true;
|
||||||
}else if(uMsg == WM_NCPAINT){
|
}if(uMsg == WM_NCHITTEST){
|
||||||
if(!isCompositionEnabled()){
|
|
||||||
*result = WVR_REDRAW;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}else if(uMsg == WM_NCACTIVATE){
|
|
||||||
if(!isCompositionEnabled()){
|
|
||||||
*result = 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}else if(uMsg == WM_NCHITTEST){
|
|
||||||
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
|
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
|
||||||
if (*result == HTNOWHERE) {
|
if (*result == HTNOWHERE) {
|
||||||
*result = HTZOOM;
|
*result = HTZOOM;
|
||||||
@ -256,24 +260,34 @@ void FluFramelessHelper::componentComplete(){
|
|||||||
o = o->parent();
|
o = o->parent();
|
||||||
}
|
}
|
||||||
if(!window.isNull()){
|
if(!window.isNull()){
|
||||||
|
_stayTop = QQmlProperty(window,"stayTop");
|
||||||
|
_screen = QQmlProperty(window,"screen");
|
||||||
|
_fixSize = QQmlProperty(window,"fixSize");
|
||||||
|
_originalPos = QQmlProperty(window,"_originalPos");
|
||||||
|
_accentColor = QQmlProperty(window,"_accentColor");
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
// window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
|
if(isCompositionEnabled()){
|
||||||
_nativeEvent =new FramelessEventFilter(this);
|
_accentColor.write(getAccentColor());
|
||||||
qApp->installNativeEventFilter(_nativeEvent);
|
_nativeEvent =new FramelessEventFilter(this);
|
||||||
HWND hwnd = reinterpret_cast<HWND>(window->winId());
|
qApp->installNativeEventFilter(_nativeEvent);
|
||||||
DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
|
HWND hwnd = reinterpret_cast<HWND>(window->winId());
|
||||||
if(resizeable()){
|
DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
|
||||||
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CAPTION);
|
if(resizeable()){
|
||||||
|
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CAPTION);
|
||||||
|
}else{
|
||||||
|
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);
|
||||||
|
}
|
||||||
|
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
||||||
|
if(_fixSize.read().toBool()){
|
||||||
|
window->setMaximumSize(window->size());
|
||||||
|
window->setMinimumSize(window->size());
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);
|
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
|
||||||
}
|
}
|
||||||
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
|
||||||
#else
|
#else
|
||||||
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
|
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
|
||||||
#endif
|
#endif
|
||||||
_stayTop = QQmlProperty(window,"stayTop");
|
|
||||||
_screen = QQmlProperty(window,"screen");
|
|
||||||
_originalPos = QQmlProperty(window,"_originalPos");
|
|
||||||
_onStayTopChange();
|
_onStayTopChange();
|
||||||
_stayTop.connectNotifySignal(this,SLOT(_onStayTopChange()));
|
_stayTop.connectNotifySignal(this,SLOT(_onStayTopChange()));
|
||||||
_screen.connectNotifySignal(this,SLOT(_onScreenChanged()));
|
_screen.connectNotifySignal(this,SLOT(_onScreenChanged()));
|
||||||
@ -334,8 +348,10 @@ FluFramelessHelper::~FluFramelessHelper(){
|
|||||||
if (!window.isNull()) {
|
if (!window.isNull()) {
|
||||||
window->setFlags(Qt::Window);
|
window->setFlags(Qt::Window);
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
qApp->removeNativeEventFilter(_nativeEvent);
|
if(isCompositionEnabled()){
|
||||||
delete _nativeEvent;
|
qApp->removeNativeEventFilter(_nativeEvent);
|
||||||
|
delete _nativeEvent;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
window->removeEventFilter(this);
|
window->removeEventFilter(this);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,8 @@ private:
|
|||||||
QQmlProperty _stayTop;
|
QQmlProperty _stayTop;
|
||||||
QQmlProperty _screen;
|
QQmlProperty _screen;
|
||||||
QQmlProperty _originalPos;
|
QQmlProperty _originalPos;
|
||||||
|
QQmlProperty _fixSize;
|
||||||
|
QQmlProperty _accentColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLUFRAMELESSHELPER_H
|
#endif // FLUFRAMELESSHELPER_H
|
||||||
|
@ -196,17 +196,42 @@ int FluTools::cursorScreenIndex(){
|
|||||||
return screenIndex;
|
return screenIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FluTools::windowBuildNumber(){
|
||||||
|
#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();
|
||||||
|
return buildNumber;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
bool FluTools::isWindows11OrGreater(){
|
bool FluTools::isWindows11OrGreater(){
|
||||||
static QVariant var;
|
static QVariant var;
|
||||||
if(var.isNull()){
|
if(var.isNull()){
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
QSettings regKey {QString::fromUtf8("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), QSettings::NativeFormat};
|
auto buildNumber = windowBuildNumber();
|
||||||
if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) {
|
if(buildNumber>=22000){
|
||||||
auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt();
|
var = QVariant::fromValue(true);
|
||||||
if(buildNumber>=22000){
|
return true;
|
||||||
var = QVariant::fromValue(true);
|
}
|
||||||
return true;
|
#endif
|
||||||
}
|
var = QVariant::fromValue(false);
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
return var.toBool();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FluTools::isWindows10OrGreater(){
|
||||||
|
static QVariant var;
|
||||||
|
if(var.isNull()){
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
auto buildNumber = windowBuildNumber();
|
||||||
|
if(buildNumber>=10240){
|
||||||
|
var = QVariant::fromValue(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
var = QVariant::fromValue(false);
|
var = QVariant::fromValue(false);
|
||||||
|
@ -51,7 +51,9 @@ public:
|
|||||||
Q_INVOKABLE QPoint cursorPos();
|
Q_INVOKABLE QPoint cursorPos();
|
||||||
Q_INVOKABLE QIcon windowIcon();
|
Q_INVOKABLE QIcon windowIcon();
|
||||||
Q_INVOKABLE int cursorScreenIndex();
|
Q_INVOKABLE int cursorScreenIndex();
|
||||||
|
Q_INVOKABLE int windowBuildNumber();
|
||||||
Q_INVOKABLE bool isWindows11OrGreater();
|
Q_INVOKABLE bool isWindows11OrGreater();
|
||||||
|
Q_INVOKABLE bool isWindows10OrGreater();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLUTOOLS_H
|
#endif // FLUTOOLS_H
|
||||||
|
@ -40,7 +40,12 @@ Window {
|
|||||||
property bool showStayTop: true
|
property bool showStayTop: true
|
||||||
property bool autoMaximize: false
|
property bool autoMaximize: false
|
||||||
property bool useSystemAppBar
|
property bool useSystemAppBar
|
||||||
property color resizeBorderColor: FluTheme.dark ? Qt.rgba(80/255,80/255,80/255,1) : Qt.rgba(210/255,210/255,210/255,1)
|
property color resizeBorderColor: {
|
||||||
|
if(window.active){
|
||||||
|
return _accentColor
|
||||||
|
}
|
||||||
|
return FluTheme.dark ? "#3D3D3E" : "#A7A7A7"
|
||||||
|
}
|
||||||
property int resizeBorderWidth: 1
|
property int resizeBorderWidth: 1
|
||||||
property var closeListener: function(event){
|
property var closeListener: function(event){
|
||||||
if(closeDestory){
|
if(closeDestory){
|
||||||
@ -55,6 +60,7 @@ Window {
|
|||||||
signal firstVisible()
|
signal firstVisible()
|
||||||
property point _offsetXY : Qt.point(0,0)
|
property point _offsetXY : Qt.point(0,0)
|
||||||
property var _originalPos
|
property var _originalPos
|
||||||
|
property color _accentColor : FluTheme.dark ? "#333333" : "#6E6E6E"
|
||||||
id:window
|
id:window
|
||||||
color:"transparent"
|
color:"transparent"
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
@ -192,7 +198,7 @@ Window {
|
|||||||
id:layout_container
|
id:layout_container
|
||||||
anchors{
|
anchors{
|
||||||
fill:parent
|
fill:parent
|
||||||
topMargin: _offsetXY.x
|
topMargin: _offsetXY.y
|
||||||
}
|
}
|
||||||
onWidthChanged: {
|
onWidthChanged: {
|
||||||
window.appBar.width = width
|
window.appBar.width = width
|
||||||
@ -245,7 +251,21 @@ Window {
|
|||||||
border.width: window.resizeBorderWidth
|
border.width: window.resizeBorderWidth
|
||||||
border.color: window.resizeBorderColor
|
border.color: window.resizeBorderColor
|
||||||
visible: {
|
visible: {
|
||||||
if(window.useSystemAppBar){
|
if(window.useSystemAppBar || FluTools.isWindows10OrGreater()){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rectangle{
|
||||||
|
height: 1
|
||||||
|
width: parent.width
|
||||||
|
color: window.resizeBorderColor
|
||||||
|
visible: {
|
||||||
|
if(window.useSystemAppBar || !FluTools.isWin()){
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){
|
if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){
|
||||||
|
@ -39,7 +39,12 @@ Window {
|
|||||||
property bool showStayTop: true
|
property bool showStayTop: true
|
||||||
property bool autoMaximize: false
|
property bool autoMaximize: false
|
||||||
property bool useSystemAppBar
|
property bool useSystemAppBar
|
||||||
property color resizeBorderColor: FluTheme.dark ? Qt.rgba(80/255,80/255,80/255,1) : Qt.rgba(210/255,210/255,210/255,1)
|
property color resizeBorderColor: {
|
||||||
|
if(window.active){
|
||||||
|
return _accentColor
|
||||||
|
}
|
||||||
|
return FluTheme.dark ? "#3D3D3E" : "#A7A7A7"
|
||||||
|
}
|
||||||
property int resizeBorderWidth: 1
|
property int resizeBorderWidth: 1
|
||||||
property var closeListener: function(event){
|
property var closeListener: function(event){
|
||||||
if(closeDestory){
|
if(closeDestory){
|
||||||
@ -54,6 +59,7 @@ Window {
|
|||||||
signal firstVisible()
|
signal firstVisible()
|
||||||
property point _offsetXY : Qt.point(0,0)
|
property point _offsetXY : Qt.point(0,0)
|
||||||
property var _originalPos
|
property var _originalPos
|
||||||
|
property color _accentColor : FluTheme.dark ? "#333333" : "#6E6E6E"
|
||||||
id:window
|
id:window
|
||||||
color:"transparent"
|
color:"transparent"
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
@ -191,7 +197,7 @@ Window {
|
|||||||
id:layout_container
|
id:layout_container
|
||||||
anchors{
|
anchors{
|
||||||
fill:parent
|
fill:parent
|
||||||
topMargin: _offsetXY.x
|
topMargin: _offsetXY.y
|
||||||
}
|
}
|
||||||
onWidthChanged: {
|
onWidthChanged: {
|
||||||
window.appBar.width = width
|
window.appBar.width = width
|
||||||
@ -244,7 +250,21 @@ Window {
|
|||||||
border.width: window.resizeBorderWidth
|
border.width: window.resizeBorderWidth
|
||||||
border.color: window.resizeBorderColor
|
border.color: window.resizeBorderColor
|
||||||
visible: {
|
visible: {
|
||||||
if(window.useSystemAppBar){
|
if(window.useSystemAppBar || FluTools.isWindows10OrGreater()){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rectangle{
|
||||||
|
height: 1
|
||||||
|
width: parent.width
|
||||||
|
color: window.resizeBorderColor
|
||||||
|
visible: {
|
||||||
|
if(window.useSystemAppBar || !FluTools.isWin()){
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){
|
if(window.visibility == Window.Maximized || window.visibility == Window.FullScreen){
|
||||||
|
Loading…
Reference in New Issue
Block a user