FluentUI/src/controls/FluAppBar.qml

161 lines
4.4 KiB
QML
Raw Normal View History

2023-03-30 21:52:55 +08:00
import QtQuick
import QtQuick.Controls
import QtQuick.Window
import QtQuick.Layouts
import FluentUI
2023-02-27 18:46:39 +08:00
Rectangle{
2023-03-28 17:53:46 +08:00
property string title: ""
2023-03-28 21:37:10 +08:00
property color textColor: FluTheme.dark ? "#FFFFFF" : "#000000"
2023-03-27 18:24:35 +08:00
property bool showDark: false
property bool showFps: false
property var window: Window.window
2023-03-28 21:37:10 +08:00
property color borerlessColor : FluTheme.dark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark
2023-03-27 18:24:35 +08:00
property bool resizable: {
if(window == null){
return false
}
return !(window.minimumHeight === window.maximumHeight && window.maximumWidth === window.minimumWidth)
}
id:root
2023-03-28 11:53:25 +08:00
color: Qt.rgba(0,0,0,0)
2023-03-28 21:37:10 +08:00
visible: FluTheme.frameless
2023-03-28 11:53:25 +08:00
height: visible ? 30 : 0
2023-03-31 22:54:23 +08:00
opacity: visible
2023-03-06 12:09:06 +08:00
z: 65535
2023-03-02 00:35:58 +08:00
2023-03-06 18:08:01 +08:00
TapHandler {
onTapped: if (tapCount === 2) toggleMaximized()
gesturePolicy: TapHandler.DragThreshold
}
DragHandler {
target: null
grabPermissions: TapHandler.CanTakeOverFromAnything
onActiveChanged: if (active) { window.startSystemMove(); }
2023-02-27 18:46:39 +08:00
}
FluText {
text: title
anchors{
verticalCenter: parent.verticalCenter
left: parent.left
2023-03-10 18:08:32 +08:00
leftMargin: 10
2023-02-27 18:46:39 +08:00
}
2023-03-06 14:22:13 +08:00
color:root.textColor
2023-02-27 18:46:39 +08:00
fontStyle: FluText.Title
font.pixelSize: 14
font.bold: true
}
RowLayout{
2023-03-10 18:08:32 +08:00
anchors.right: parent.right
2023-03-28 11:53:25 +08:00
height: root.height
2023-03-10 18:08:32 +08:00
spacing: 0
2023-02-27 18:46:39 +08:00
2023-03-01 11:58:30 +08:00
2023-02-27 18:46:39 +08:00
RowLayout{
Layout.alignment: Qt.AlignVCenter
2023-03-29 15:43:23 +08:00
Layout.rightMargin: 5
2023-03-03 18:19:48 +08:00
visible: showDark
2023-03-10 18:08:32 +08:00
spacing: 5
2023-02-27 18:46:39 +08:00
FluText{
text:"夜间模式"
2023-03-06 14:22:13 +08:00
color:root.textColor
2023-02-27 18:46:39 +08:00
}
FluToggleSwitch{
2023-03-28 21:37:10 +08:00
selected: FluTheme.dark
2023-03-12 22:36:31 +08:00
clickFunc:function(){
2023-03-28 21:37:10 +08:00
FluTheme.dark = !FluTheme.dark
2023-02-27 18:46:39 +08:00
}
}
}
2023-03-06 14:22:13 +08:00
FluIconButton{
2023-03-28 11:53:25 +08:00
width: 40
height: 30
iconSource : FluentIcons.ChromeMinimize
2023-02-27 18:46:39 +08:00
Layout.alignment: Qt.AlignVCenter
2023-03-28 11:53:25 +08:00
iconSize: 11
2023-03-06 14:22:13 +08:00
text:"最小化"
2023-03-28 11:53:25 +08:00
radius: 0
2023-03-06 14:22:13 +08:00
textColor: root.textColor
2023-03-28 17:53:46 +08:00
color:{
2023-03-28 21:37:10 +08:00
if(FluTheme.dark){
2023-03-28 17:53:46 +08:00
if(hovered){
return Qt.rgba(1,1,1,0.06)
}
return Qt.rgba(0,0,0,0)
}else{
if(hovered){
return Qt.rgba(0,0,0,0.06)
}
return Qt.rgba(0,0,0,0)
}
}
2023-03-06 14:22:13 +08:00
onClicked: {
2023-03-06 18:08:01 +08:00
window.showMinimized()
2023-02-27 18:46:39 +08:00
}
}
2023-03-06 14:22:13 +08:00
FluIconButton{
2023-03-28 11:53:25 +08:00
width: 40
height: 30
2023-03-06 14:22:13 +08:00
property bool isRestore:{
2023-03-06 18:08:01 +08:00
if(window == null)
2023-02-27 18:46:39 +08:00
return false
2023-03-06 18:08:01 +08:00
return Window.Maximized === window.visibility
2023-03-06 12:09:06 +08:00
}
2023-03-28 11:53:25 +08:00
iconSource : isRestore ? FluentIcons.ChromeRestore : FluentIcons.ChromeMaximize
2023-03-28 17:53:46 +08:00
color:{
2023-03-28 21:37:10 +08:00
if(FluTheme.dark){
2023-03-28 17:53:46 +08:00
if(hovered){
return Qt.rgba(1,1,1,0.06)
}
return Qt.rgba(0,0,0,0)
}else{
if(hovered){
return Qt.rgba(0,0,0,0.06)
}
return Qt.rgba(0,0,0,0)
}
}
2023-02-27 18:46:39 +08:00
Layout.alignment: Qt.AlignVCenter
2023-03-02 00:35:58 +08:00
visible: resizable
2023-03-28 11:53:25 +08:00
radius: 0
2023-03-06 14:22:13 +08:00
textColor: root.textColor
text:isRestore?"向下还原":"最大化"
2023-03-28 11:53:25 +08:00
iconSize: 11
2023-03-06 14:22:13 +08:00
onClicked: {
toggleMaximized()
2023-02-27 18:46:39 +08:00
}
}
2023-03-06 14:22:13 +08:00
FluIconButton{
2023-03-28 11:53:25 +08:00
iconSource : FluentIcons.ChromeClose
2023-02-27 18:46:39 +08:00
Layout.alignment: Qt.AlignVCenter
2023-03-06 14:22:13 +08:00
text:"关闭"
2023-03-28 11:53:25 +08:00
width: 40
height: 30
radius: 0
iconSize: 10
textColor: hovered ? Qt.rgba(1,1,1,1) : root.textColor
color:hovered ? Qt.rgba(251/255,115/255,115/255,1) : "#00000000"
2023-03-06 14:22:13 +08:00
onClicked: {
Window.window.close()
2023-02-27 18:46:39 +08:00
}
}
}
2023-03-27 18:24:35 +08:00
function toggleMaximized() {
if(!resizable)
return
if (window.visibility === Window.Maximized) {
window.showNormal();
} else {
window.showMaximized();
}
}
2023-02-27 18:46:39 +08:00
}