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