Zhao Yuhang
2025-02-09 f1d4f07dcb8bd93578abb2fc1e289050d7e1c3ee
examples/qml/main.qml
@@ -1,6 +1,6 @@
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Basic 2.15
import Qt.labs.platform 1.1
import QWindowKit 1.0
@@ -13,6 +13,7 @@
    Component.onCompleted: {
        windowAgent.setup(window)
        window.visible = true
        delayInitTimer.start()
    }
    QtObject {
@@ -31,26 +32,33 @@
        onTriggered: timeLabel.text = Qt.formatTime(new Date(), "hh:mm:ss")
    }
    Timer {
        id: delayInitTimer
        interval: 100
        running: false
        repeat: false
        onTriggered: windowAgent.setWindowAttribute("dark-mode", true)
    }
    WindowAgent {
        id: windowAgent
    }
    MouseArea {
        anchors.fill: parent
    TapHandler {
        acceptedButtons: Qt.RightButton
        onClicked: contextMenu.open()
        onTapped: contextMenu.open()
    }
    Rectangle {
        id: titleBar
        anchors {
            top: parent.top
            topMargin: 1
            left: parent.left
            right: parent.right
        }
        height: 32
        color: window.active ? "#3C3C3C" : "#505050"
        //color: window.active ? "#3C3C3C" : "#505050"
        color: "transparent"
        Component.onCompleted: windowAgent.setTitleBar(titleBar)
        Image {
@@ -64,6 +72,8 @@
            height: 18
            mipmap: true
            source: "qrc:///app/example.png"
            fillMode: Image.PreserveAspectFit
            Component.onCompleted: windowAgent.setSystemButton(WindowAgent.WindowIcon, iconButton)
        }
        Text {
@@ -140,6 +150,12 @@
            bold: true
        }
        color: "#FEFEFE"
        Component.onCompleted: {
            if ($curveRenderingAvailable) {
                console.log("Curve rendering for text is available.")
                timeLabel.renderType = Text.CurveRendering
            }
        }
    }
    Menu {
@@ -163,6 +179,7 @@
            MenuItem {
                text: qsTr("Dark")
                checkable: true
                checked: true
                onTriggered: windowAgent.setWindowAttribute("dark-mode", true)
            }
        }
@@ -178,11 +195,28 @@
            MenuItem {
                enabled: Qt.platform.os === "windows"
                text: qsTr("None")
                checkable: true
                checked: true
                onTriggered: {
                    window.color = darkStyle.windowBackgroundColor
                    windowAgent.setWindowAttribute("dwm-blur", false)
                    windowAgent.setWindowAttribute("acrylic-material", false)
                    windowAgent.setWindowAttribute("mica", false)
                    windowAgent.setWindowAttribute("mica-alt", false)
                }
            }
            MenuItem {
                enabled: Qt.platform.os === "windows"
                text: qsTr("DWM blur")
                checkable: true
                onTriggered: {
                    window.color = checked ? "transparent" : darkStyle.windowBackgroundColor
                    windowAgent.setWindowAttribute("dwm-blur", checked)
                    window.color = "transparent"
                    windowAgent.setWindowAttribute("acrylic-material", false)
                    windowAgent.setWindowAttribute("mica", false)
                    windowAgent.setWindowAttribute("mica-alt", false)
                    windowAgent.setWindowAttribute("dwm-blur", true)
                }
            }
@@ -191,8 +225,11 @@
                text: qsTr("Acrylic material")
                checkable: true
                onTriggered: {
                    window.color = checked ? "transparent" : darkStyle.windowBackgroundColor
                    windowAgent.setWindowAttribute("acrylic-material", checked)
                    window.color = "transparent"
                    windowAgent.setWindowAttribute("dwm-blur", false)
                    windowAgent.setWindowAttribute("mica", false)
                    windowAgent.setWindowAttribute("mica-alt", false)
                    windowAgent.setWindowAttribute("acrylic-material", true)
                }
            }
@@ -201,8 +238,11 @@
                text: qsTr("Mica")
                checkable: true
                onTriggered: {
                    window.color = checked ? "transparent" : darkStyle.windowBackgroundColor
                    windowAgent.setWindowAttribute("mica", checked)
                    window.color = "transparent"
                    windowAgent.setWindowAttribute("dwm-blur", false)
                    windowAgent.setWindowAttribute("acrylic-material", false)
                    windowAgent.setWindowAttribute("mica-alt", false)
                    windowAgent.setWindowAttribute("mica", true)
                }
            }
@@ -211,8 +251,11 @@
                text: qsTr("Mica Alt")
                checkable: true
                onTriggered: {
                    window.color = checked ? "transparent" : darkStyle.windowBackgroundColor
                    windowAgent.setWindowAttribute("mica-alt", checked)
                    window.color = "transparent"
                    windowAgent.setWindowAttribute("dwm-blur", false)
                    windowAgent.setWindowAttribute("acrylic-material", false)
                    windowAgent.setWindowAttribute("mica", false)
                    windowAgent.setWindowAttribute("mica-alt", true)
                }
            }
        }