File: Shell.qml

package info (click to toggle)
qtmir 0.8.0~git20230223.bd21224-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,568 kB
  • sloc: cpp: 22,847; python: 304; xml: 271; ansic: 87; makefile: 20; sh: 12
file content (172 lines) | stat: -rw-r--r-- 5,257 bytes parent folder | download | duplicates (3)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import QtQuick 2.4
import QtMir.Application 0.1
import QtMir.DemoShell.Pointer 0.1

FocusScope {
    id: root
    focus: true

    Image {
        id: unityLogo
        source: "UnityLogo.png"
        fillMode: Image.PreserveAspectFit
        anchors.centerIn: parent
        width: 600
        height: 600

        RotationAnimation {
            id: logoAnimation
            target: unityLogo
            from: 0
            to: 359
            duration: 3000
            easing.type: Easing.Linear
            loops: Animation.Infinite
        }

        MultiPointTouchArea {
            anchors.fill: parent
            minimumTouchPoints:1
            maximumTouchPoints:1
            onPressed: {
                if (logoAnimation.paused) {
                    logoAnimation.resume();
                } else if (logoAnimation.running) {
                    logoAnimation.pause();
                } else {
                    logoAnimation.start();
                }
            }
        }
    }


    WindowModel {
        id: windowModel;
    }

    Item {
        id: windowViewContainer
        anchors.fill: parent

        Repeater {
            model: windowModel

            delegate: MirSurfaceItem {
                id: surfaceItem
                surface: model.surface
                consumesInput: true // QUESTION: why is this non-default?
                x: surface.position.x
                y: surface.position.y
                width: surface.size.width
                height: surface.size.height
                focus: surface.focused
                visible: surface.visible
                fillMode: MirSurfaceItem.PadOrCrop

                Rectangle {
                    anchors { top: parent.bottom; right: parent.right }
                    width: childrenRect.width
                    height: childrenRect.height
                    color: surface.focused ? "red" : "lightsteelblue"
                    opacity: 0.8
                    Text {
                        text: surface.position.x + "," + surface.position.y + " " + surface.size.width + "x" + surface.size.height
                        font.pixelSize: 10
                    }
                }

                Rectangle { anchors.fill: parent; z: -1; color: "black"; opacity: 0.3 }
            }
        }
    }

    Button {
        anchors { right: parent.right; top: parent.top }
        height: 30
        width: 80
        text: "Quit"
        onClicked: Qt.quit()
    }

    WindowModelDebugView {
        anchors { right: parent.right; bottom: parent.bottom }
        model: windowModel
    }

    Text {
        anchors { left: parent.left; bottom: parent.bottom }
        text: "Move window: Ctrl+click\n
Resize window: Ctrl+Right click"
    }

    Rectangle {
        id: mousePointer
        color: "black"
        width: 6
        height: 10
        x: PointerPosition.x// - window.screen.position.x
        y: PointerPosition.y// - window.screen.position.y
    }

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        hoverEnabled: false
        property variant window: null
        property int initialWindowXPosition
        property int initialWindowYPosition
        property int initialWindowWidth
        property int initialWindowHeight
        property int initialMouseXPosition
        property int initialMouseYPosition
        property var action

        function moveWindowBy(window, delta) {
            window.surface.requestedPosition = Qt.point(initialWindowXPosition + delta.x,
                                                        initialWindowYPosition + delta.y);
        }
        function resizeWindowBy(window, delta) {
            window.surface.resize(Qt.size(initialWindowWidth + delta.x,
                                          initialWindowHeight + delta.y))
        }

        onPressed: {
            if (mouse.modifiers & Qt.ControlModifier) {
                window = windowViewContainer.childAt(mouse.x, mouse.y)
                if (!window) return;

                if (mouse.button == Qt.LeftButton) {
                    initialWindowXPosition = window.surface.position.x
                    initialWindowYPosition = window.surface.position.y
                    action = moveWindowBy
                } else if (mouse.button == Qt.RightButton) {
                    initialWindowHeight = window.surface.size.height
                    initialWindowWidth = window.surface.size.width
                    action = resizeWindowBy
                }
                initialMouseXPosition = mouse.x
                initialMouseYPosition = mouse.y
            } else {
                mouse.accepted = false
            }
        }

        onPositionChanged: {
            if (!window) {
                mouse.accepted = false
                return
            }
            action(window, Qt.point(mouse.x - initialMouseXPosition, mouse.y - initialMouseYPosition))
        }

        onReleased: {
            if (!window) {
                mouse.accepted = false
                return
            }
            action(window, Qt.point(mouse.x - initialMouseXPosition, mouse.y - initialMouseYPosition))
            window = null;
        }
    }
}