This commit is contained in:
zhuzichu 2023-10-20 18:04:58 +08:00
parent 83f94630f1
commit 5f6d66b6ce
4 changed files with 102 additions and 1 deletions

View File

@ -11,6 +11,8 @@ Rectangle{
property string restoreText : "向下还原"
property string maximizeText : "最大化"
property string closeText : "关闭"
property string stayTopText : "置顶"
property string stayTopCancelText : "取消置顶"
property color textColor: FluTheme.dark ? "#FFFFFF" : "#000000"
property color minimizeNormalColor: Qt.rgba(0,0,0,0)
property color minimizeHoverColor: FluTheme.dark ? Qt.rgba(1,1,1,0.03) : Qt.rgba(0,0,0,0.03)
@ -25,6 +27,7 @@ Rectangle{
property bool showClose: true
property bool showMinimize: true
property bool showMaximize: true
property bool showStayTop: true
property bool titleVisible: true
property url icon
property int iconSize: 20
@ -42,6 +45,11 @@ Rectangle{
property var closeClickListener : function(){
d.win.close()
}
property var stayTopClickListener: function(){
if(d.win instanceof FluWindow){
d.win.stayTop = !d.win.stayTop
}
}
property var darkClickListener: function(){
if(FluTheme.dark){
FluTheme.darkMode = FluThemeType.Light
@ -57,6 +65,12 @@ Rectangle{
Item{
id:d
property var win: Window.window
property bool stayTop: {
if(d.win instanceof FluWindow){
return d.win.stayTop
}
return false
}
property bool isRestore: win && Window.Maximized === win.visibility
property bool resizable: win && !(win.minimumHeight === win.maximumHeight && win.maximumWidth === win.minimumWidth)
}
@ -106,6 +120,24 @@ Rectangle{
textRight: false
clickListener:()=> darkClickListener(btn_dark)
}
FluIconButton{
id:btn_stay_top
Layout.preferredWidth: 40
Layout.preferredHeight: 30
iconSource : FluentIcons.Pinned
Layout.alignment: Qt.AlignVCenter
iconSize: 13
visible: {
if(!(d.win instanceof FluWindow)){
return false
}
return showStayTop
}
text:d.stayTop ? control.stayTopCancelText : control.stayTopText
radius: 0
iconColor: d.stayTop ? (FluTheme.dark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark) : control.textColor
onClicked: stayTopClickListener()
}
FluIconButton{
id:btn_minimize
Layout.preferredWidth: 40
@ -164,6 +196,9 @@ Rectangle{
onClicked: closeClickListener()
}
}
function stayTopButton(){
return btn_stay_top
}
function minimizeButton(){
return btn_minimize
}

View File

@ -20,6 +20,7 @@ Window {
}
return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(237/255,237/255,237/255,1)
}
property bool stayTop: false
property var _pageRegister
property string _route
property var closeListener: function(event){
@ -33,9 +34,13 @@ Window {
signal initArgument(var argument)
id:window
color:"transparent"
onStayTopChanged: {
d.changedStayTop()
}
Component.onCompleted: {
lifecycle.onCompleted(window)
initArgument(argument)
d.changedStayTop()
}
Component.onDestruction: {
lifecycle.onDestruction()
@ -43,6 +48,16 @@ Window {
onVisibleChanged: {
lifecycle.onVisible(visible)
}
QtObject{
id:d
function changedStayTop(){
if(window.stayTop){
window.flags = window.flags | Qt.WindowStaysOnTopHint
}else{
window.flags = window.flags &~ Qt.WindowStaysOnTopHint
}
}
}
Connections{
target: window
function onClosing(event){closeListener(event)}
@ -173,6 +188,7 @@ Window {
setHitTestVisible(title_bar.minimizeButton())
setHitTestVisible(title_bar.maximizeButton())
setHitTestVisible(title_bar.closeButton())
setHitTestVisible(title_bar.stayTopButton())
setWindowFixedSize(fixSize)
title_bar.maximizeButton.visible = !fixSize
if (blurBehindWindowEnabled)

View File

@ -11,6 +11,8 @@ Rectangle{
property string restoreText : "向下还原"
property string maximizeText : "最大化"
property string closeText : "关闭"
property string stayTopText : "置顶"
property string stayTopCancelText : "取消置顶"
property color textColor: FluTheme.dark ? "#FFFFFF" : "#000000"
property color minimizeNormalColor: Qt.rgba(0,0,0,0)
property color minimizeHoverColor: FluTheme.dark ? Qt.rgba(1,1,1,0.03) : Qt.rgba(0,0,0,0.03)
@ -25,6 +27,7 @@ Rectangle{
property bool showClose: true
property bool showMinimize: true
property bool showMaximize: true
property bool showStayTop: true
property bool titleVisible: true
property url icon
property int iconSize: 20
@ -42,6 +45,11 @@ Rectangle{
property var closeClickListener : function(){
d.win.close()
}
property var stayTopClickListener: function(){
if(d.win instanceof FluWindow){
d.win.stayTop = !d.win.stayTop
}
}
property var darkClickListener: function(){
if(FluTheme.dark){
FluTheme.darkMode = FluThemeType.Light
@ -57,6 +65,12 @@ Rectangle{
Item{
id:d
property var win: Window.window
property bool stayTop: {
if(d.win instanceof FluWindow){
return d.win.stayTop
}
return false
}
property bool isRestore: win && Window.Maximized === win.visibility
property bool resizable: win && !(win.minimumHeight === win.maximumHeight && win.maximumWidth === win.minimumWidth)
}
@ -106,6 +120,24 @@ Rectangle{
textRight: false
clickListener:()=> darkClickListener(btn_dark)
}
FluIconButton{
id:btn_stay_top
Layout.preferredWidth: 40
Layout.preferredHeight: 30
iconSource : FluentIcons.Pinned
Layout.alignment: Qt.AlignVCenter
iconSize: 13
visible: {
if(!(d.win instanceof FluWindow)){
return false
}
return showStayTop
}
text:d.stayTop ? control.stayTopCancelText : control.stayTopText
radius: 0
iconColor: d.stayTop ? (FluTheme.dark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark) : control.textColor
onClicked: stayTopClickListener()
}
FluIconButton{
id:btn_minimize
Layout.preferredWidth: 40
@ -164,6 +196,9 @@ Rectangle{
onClicked: closeClickListener()
}
}
function stayTopButton(){
return btn_stay_top
}
function minimizeButton(){
return btn_minimize
}
@ -177,4 +212,3 @@ Rectangle{
return btn_dark
}
}

View File

@ -19,6 +19,7 @@ Window {
}
return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(237/255,237/255,237/255,1)
}
property bool stayTop: false
property var _pageRegister
property string _route
property var closeListener: function(event){
@ -32,9 +33,13 @@ Window {
signal initArgument(var argument)
id:window
color:"transparent"
onStayTopChanged: {
d.changedStayTop()
}
Component.onCompleted: {
lifecycle.onCompleted(window)
initArgument(argument)
d.changedStayTop()
}
Component.onDestruction: {
lifecycle.onDestruction()
@ -42,6 +47,16 @@ Window {
onVisibleChanged: {
lifecycle.onVisible(visible)
}
QtObject{
id:d
function changedStayTop(){
if(window.stayTop){
window.flags = window.flags | Qt.WindowStaysOnTopHint
}else{
window.flags = window.flags &~ Qt.WindowStaysOnTopHint
}
}
}
Connections{
target: window
function onClosing(event){closeListener(event)}
@ -172,6 +187,7 @@ Window {
setHitTestVisible(title_bar.minimizeButton())
setHitTestVisible(title_bar.maximizeButton())
setHitTestVisible(title_bar.closeButton())
setHitTestVisible(title_bar.stayTopButton())
setWindowFixedSize(fixSize)
title_bar.maximizeButton.visible = !fixSize
if (blurBehindWindowEnabled)