FluAppBar.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Window
  4. import QtQuick.Layouts
  5. import FluentUI
  6. Rectangle{
  7. property string title: ""
  8. property string darkText : "夜间模式"
  9. property string minimizeText : "最小化"
  10. property string restoreText : "向下还原"
  11. property string maximizeText : "最大化"
  12. property string closeText : "关闭"
  13. property color textColor: FluTheme.dark ? "#FFFFFF" : "#000000"
  14. property color minimizeNormalColor: Qt.rgba(0,0,0,0)
  15. property color minimizeHoverColor: FluTheme.dark ? Qt.rgba(1,1,1,0.1) : Qt.rgba(0,0,0,0.06)
  16. property color maximizeNormalColor: Qt.rgba(0,0,0,0)
  17. property color maximizeHoverColor: FluTheme.dark ? Qt.rgba(1,1,1,0.1) : Qt.rgba(0,0,0,0.06)
  18. property color closeNormalColor: Qt.rgba(0,0,0,0)
  19. property color closeHoverColor: Qt.rgba(251/255,115/255,115/255,1)
  20. property bool showDark: false
  21. property color borerlessColor : FluTheme.dark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark
  22. Item{
  23. id:d
  24. property var win: Window.window
  25. property bool isRestore: win && Window.Maximized === win.visibility
  26. property bool resizable: win && !(win.minimumHeight === win.maximumHeight && win.maximumWidth === win.minimumWidth)
  27. }
  28. id:root
  29. color: Qt.rgba(0,0,0,0)
  30. visible: FluTheme.frameless
  31. height: visible ? 30 : 0
  32. opacity: visible
  33. z: 65535
  34. TapHandler {
  35. onTapped: if (tapCount === 2) toggleMaximized()
  36. gesturePolicy: TapHandler.DragThreshold
  37. }
  38. DragHandler {
  39. target: null
  40. grabPermissions: TapHandler.CanTakeOverFromAnything
  41. onActiveChanged: if (active) { d.win.startSystemMove(); }
  42. }
  43. FluText {
  44. text: title
  45. anchors{
  46. verticalCenter: parent.verticalCenter
  47. left: parent.left
  48. leftMargin: 10
  49. }
  50. color:root.textColor
  51. fontStyle: FluText.Title
  52. font.pixelSize: 14
  53. font.bold: true
  54. }
  55. RowLayout{
  56. anchors.right: parent.right
  57. height: root.height
  58. spacing: 0
  59. RowLayout{
  60. Layout.alignment: Qt.AlignVCenter
  61. Layout.rightMargin: 5
  62. visible: showDark
  63. spacing: 5
  64. FluText{
  65. text:darkText
  66. color:root.textColor
  67. }
  68. FluToggleSwitch{
  69. selected: FluTheme.dark
  70. clickFunc:function(){
  71. if(FluTheme.dark){
  72. FluTheme.darkMode = FluDarkMode.Light
  73. }else{
  74. FluTheme.darkMode = FluDarkMode.Dark
  75. }
  76. }
  77. }
  78. }
  79. FluIconButton{
  80. width: 40
  81. height: 30
  82. iconSource : FluentIcons.ChromeMinimize
  83. Layout.alignment: Qt.AlignVCenter
  84. iconSize: 11
  85. text:minimizeText
  86. radius: 0
  87. iconColor: root.textColor
  88. color: hovered ? minimizeHoverColor : minimizeNormalColor
  89. onClicked: {
  90. d.win.showMinimized()
  91. }
  92. }
  93. FluIconButton{
  94. width: 40
  95. height: 30
  96. iconSource : d.isRestore ? FluentIcons.ChromeRestore : FluentIcons.ChromeMaximize
  97. color: hovered ? maximizeHoverColor : maximizeNormalColor
  98. Layout.alignment: Qt.AlignVCenter
  99. visible: d.resizable
  100. radius: 0
  101. iconColor: root.textColor
  102. text:d.isRestore?restoreText:maximizeText
  103. iconSize: 11
  104. onClicked: {
  105. toggleMaximized()
  106. }
  107. }
  108. FluIconButton{
  109. iconSource : FluentIcons.ChromeClose
  110. Layout.alignment: Qt.AlignVCenter
  111. text:closeText
  112. width: 40
  113. height: 30
  114. radius: 0
  115. iconSize: 10
  116. iconColor: hovered ? Qt.rgba(1,1,1,1) : root.textColor
  117. color:hovered ? closeHoverColor : closeNormalColor
  118. onClicked: {
  119. d.win.close()
  120. }
  121. }
  122. }
  123. function toggleMaximized() {
  124. if(!d.resizable)
  125. return
  126. if (d.win.visibility === Window.Maximized) {
  127. d.win.showNormal();
  128. } else {
  129. d.win.showMaximized();
  130. }
  131. }
  132. }