main.qml 7.8 KB

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