FramelessWindow.qml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import QtQuick 2.15
  2. import QtQuick.Window 2.15
  3. import QtQuick.Controls 2.15
  4. import Qt.labs.platform 1.1
  5. import QWindowKit 1.0
  6. Window {
  7. property bool showWhenReady: true
  8. id: window
  9. width: 800
  10. height: 600
  11. color: darkStyle.windowBackgroundColor
  12. title: qsTr("QWindowKit QtQuick Demo")
  13. Component.onCompleted: {
  14. windowAgent.setup(window)
  15. windowAgent.setWindowAttribute("dark-mode", true)
  16. if (window.showWhenReady) {
  17. window.visible = true
  18. }
  19. }
  20. QtObject {
  21. id: lightStyle
  22. }
  23. QtObject {
  24. id: darkStyle
  25. readonly property color windowBackgroundColor: "#1E1E1E"
  26. }
  27. Timer {
  28. interval: 100
  29. running: true
  30. repeat: true
  31. onTriggered: timeLabel.text = Qt.formatTime(new Date(), "hh:mm:ss")
  32. }
  33. WindowAgent {
  34. id: windowAgent
  35. }
  36. TapHandler {
  37. acceptedButtons: Qt.RightButton
  38. onTapped: contextMenu.open()
  39. }
  40. Rectangle {
  41. id: titleBar
  42. anchors {
  43. top: parent.top
  44. left: parent.left
  45. right: parent.right
  46. }
  47. height: 32
  48. //color: window.active ? "#3C3C3C" : "#505050"
  49. color: "transparent"
  50. Component.onCompleted: windowAgent.setTitleBar(titleBar)
  51. Image {
  52. id: iconButton
  53. anchors {
  54. verticalCenter: parent.verticalCenter
  55. left: parent.left
  56. leftMargin: 10
  57. }
  58. width: 18
  59. height: 18
  60. mipmap: true
  61. source: "qrc:///app/example.png"
  62. fillMode: Image.PreserveAspectFit
  63. Component.onCompleted: windowAgent.setSystemButton(WindowAgent.WindowIcon, iconButton)
  64. }
  65. Text {
  66. anchors {
  67. verticalCenter: parent.verticalCenter
  68. left: iconButton.right
  69. leftMargin: 10
  70. }
  71. horizontalAlignment: Text.AlignHCenter
  72. verticalAlignment: Text.AlignVCenter
  73. text: window.title
  74. font.pixelSize: 14
  75. color: "#ECECEC"
  76. }
  77. Row {
  78. anchors {
  79. top: parent.top
  80. right: parent.right
  81. }
  82. height: parent.height
  83. QWKButton {
  84. id: minButton
  85. height: parent.height
  86. source: "qrc:///window-bar/minimize.svg"
  87. onClicked: window.showMinimized()
  88. Component.onCompleted: windowAgent.setSystemButton(WindowAgent.Minimize, minButton)
  89. }
  90. QWKButton {
  91. id: maxButton
  92. height: parent.height
  93. source: window.visibility === Window.Maximized ? "qrc:///window-bar/restore.svg" : "qrc:///window-bar/maximize.svg"
  94. onClicked: {
  95. if (window.visibility === Window.Maximized) {
  96. window.showNormal()
  97. } else {
  98. window.showMaximized()
  99. }
  100. }
  101. Component.onCompleted: windowAgent.setSystemButton(WindowAgent.Maximize, maxButton)
  102. }
  103. QWKButton {
  104. id: closeButton
  105. height: parent.height
  106. source: "qrc:///window-bar/close.svg"
  107. background: Rectangle {
  108. color: {
  109. if (!closeButton.enabled) {
  110. return "gray";
  111. }
  112. if (closeButton.pressed) {
  113. return "#e81123";
  114. }
  115. if (closeButton.hovered) {
  116. return "#e81123";
  117. }
  118. return "transparent";
  119. }
  120. }
  121. onClicked: window.close()
  122. Component.onCompleted: windowAgent.setSystemButton(WindowAgent.Close, closeButton)
  123. }
  124. }
  125. }
  126. Label {
  127. id: timeLabel
  128. anchors.centerIn: parent
  129. font {
  130. pointSize: 75
  131. bold: true
  132. }
  133. color: "#FEFEFE"
  134. Component.onCompleted: {
  135. if ($curveRenderingAvailable) {
  136. console.log("Curve rendering for text is available.")
  137. timeLabel.renderType = Text.CurveRendering
  138. }
  139. }
  140. }
  141. Menu {
  142. id: contextMenu
  143. Menu {
  144. id: themeMenu
  145. title: qsTr("Theme")
  146. MenuItemGroup {
  147. id: themeMenuGroup
  148. items: themeMenu.items
  149. }
  150. MenuItem {
  151. text: qsTr("Light")
  152. checkable: true
  153. onTriggered: windowAgent.setWindowAttribute("dark-mode", false)
  154. }
  155. MenuItem {
  156. text: qsTr("Dark")
  157. checkable: true
  158. checked: true
  159. onTriggered: windowAgent.setWindowAttribute("dark-mode", true)
  160. }
  161. }
  162. Menu {
  163. id: specialEffectMenu
  164. title: qsTr("Special effect")
  165. MenuItemGroup {
  166. id: specialEffectMenuGroup
  167. items: specialEffectMenu.items
  168. }
  169. MenuItem {
  170. enabled: Qt.platform.os === "windows"
  171. text: qsTr("None")
  172. checkable: true
  173. checked: true
  174. onTriggered: {
  175. window.color = darkStyle.windowBackgroundColor
  176. windowAgent.setWindowAttribute("dwm-blur", false)
  177. windowAgent.setWindowAttribute("acrylic-material", false)
  178. windowAgent.setWindowAttribute("mica", false)
  179. windowAgent.setWindowAttribute("mica-alt", false)
  180. }
  181. }
  182. MenuItem {
  183. enabled: Qt.platform.os === "windows"
  184. text: qsTr("DWM blur")
  185. checkable: true
  186. onTriggered: {
  187. window.color = "transparent"
  188. windowAgent.setWindowAttribute("acrylic-material", false)
  189. windowAgent.setWindowAttribute("mica", false)
  190. windowAgent.setWindowAttribute("mica-alt", false)
  191. windowAgent.setWindowAttribute("dwm-blur", true)
  192. }
  193. }
  194. MenuItem {
  195. enabled: Qt.platform.os === "windows"
  196. text: qsTr("Acrylic material")
  197. checkable: true
  198. onTriggered: {
  199. window.color = "transparent"
  200. windowAgent.setWindowAttribute("dwm-blur", false)
  201. windowAgent.setWindowAttribute("mica", false)
  202. windowAgent.setWindowAttribute("mica-alt", false)
  203. windowAgent.setWindowAttribute("acrylic-material", true)
  204. }
  205. }
  206. MenuItem {
  207. enabled: Qt.platform.os === "windows"
  208. text: qsTr("Mica")
  209. checkable: true
  210. onTriggered: {
  211. window.color = "transparent"
  212. windowAgent.setWindowAttribute("dwm-blur", false)
  213. windowAgent.setWindowAttribute("acrylic-material", false)
  214. windowAgent.setWindowAttribute("mica-alt", false)
  215. windowAgent.setWindowAttribute("mica", true)
  216. }
  217. }
  218. MenuItem {
  219. enabled: Qt.platform.os === "windows"
  220. text: qsTr("Mica Alt")
  221. checkable: true
  222. onTriggered: {
  223. window.color = "transparent"
  224. windowAgent.setWindowAttribute("dwm-blur", false)
  225. windowAgent.setWindowAttribute("acrylic-material", false)
  226. windowAgent.setWindowAttribute("mica", false)
  227. windowAgent.setWindowAttribute("mica-alt", true)
  228. }
  229. }
  230. }
  231. }
  232. }