Zhao Yuhang
2023-12-18 44fee9aa1e3087635d1394612c6f6ceab44ba7b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QWindowKit 1.0
 
Window {
    id: window
    width: 800
    height: 600
    color: "#f0f0f0"
    title: qsTr("Hello, world!")
    Component.onCompleted: {
        windowAgent.setup(window)
        window.visible = true
    }
 
    WindowAgent {
        id: windowAgent
    }
 
    Rectangle {
        id: titleBar
        anchors {
            top: parent.top
            topMargin: 1
            left: parent.left
            right: parent.right
        }
        height: 32
        color: "white"
        Component.onCompleted: windowAgent.setTitleBar(titleBar)
 
        Text {
            anchors.centerIn: parent
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            text: window.title
            font.pixelSize: 14
            color: window.active ? "black" : "gray"
        }
 
        Row {
            anchors {
                top: parent.top
                right: parent.right
            }
            height: parent.height
 
            QWKButton {
                id: minButton
                height: parent.height
                source: "qrc:///window-bar/minimize.svg"
                onClicked: window.showMinimized()
                Component.onCompleted: windowAgent.setHitTestVisible(minButton)
            }
 
            QWKButton {
                id: maxButton
                height: parent.height
                source: window.visibility === Window.Maximized ? "qrc:///window-bar/restore.svg" : "qrc:///window-bar/maximize.svg"
                onClicked: {
                    if (window.visibility === Window.Maximized) {
                        window.showNormal()
                    } else {
                        window.showMaximized()
                    }
                }
                Component.onCompleted: windowAgent.setHitTestVisible(maxButton)
            }
 
            QWKButton {
                id: closeButton
                height: parent.height
                source: "qrc:///window-bar/close.svg"
                onClicked: window.close()
                Component.onCompleted: windowAgent.setHitTestVisible(closeButton)
            }
        }
    }
}