File: WindowBufferSized.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 (178 lines) | stat: -rw-r--r-- 5,604 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
173
174
175
176
177
178
import QtQuick 2.0
import QtMir.Application 0.1

Rectangle {
    id: root
    color: "red"

    property alias surface: surfaceItem.surface
    property bool touchMode: false

    width: surfaceItem.width + (borderThickness*2)
    height: surfaceItem.height + titleBar.height + (borderThickness*2)

    signal cloneRequested()

    onTouchModeChanged: {
        if (touchMode) {
            x -= borderThicknessTouch - borderThicknessMouse;
            width += 2*(borderThicknessTouch - borderThicknessMouse);
            y -= borderThicknessTouch - borderThicknessMouse;
            height += 2*(borderThicknessTouch - borderThicknessMouse);
        } else {
            x += borderThicknessTouch - borderThicknessMouse;
            width -= 2*(borderThicknessTouch - borderThicknessMouse);
            y += borderThicknessTouch - borderThicknessMouse;
            height -= 2*(borderThicknessTouch - borderThicknessMouse);
        }
    }

    readonly property real minWidth: 100
    readonly property real minHeight: 100

    property real borderThickness: touchMode ? borderThicknessTouch : borderThicknessMouse
    readonly property real borderThicknessMouse: 10
    readonly property real borderThicknessTouch: 40

    states: [
        State {
            name: "closed"
            when: (surface && !surface.live) || titleBar.closeRequested
        }
    ]
    transitions: [
        Transition {
            from: ""; to: "closed"
            SequentialAnimation {
                PropertyAnimation {
                    target: root
                    property: "scale"
                    easing.type: Easing.InBack
                    duration: 400
                    from: 1.0
                    to: 0.0
                }
                ScriptAction { script: { root.destroy(); } }
            }
        }
    ]


    MouseArea {
        id: resizeArea

        anchors.fill: parent

        property real startX
        property real startY
        property real startWidth
        property real startHeight
        property bool leftBorder
        property bool rightBorder
        property bool topBorder
        property bool bottomBorder
        property bool dragging
        onPressedChanged: {
            if (pressed) {
                var pos = mapToItem(root.parent, mouseX, mouseY);
                startX = pos.x;
                startY = pos.y;
                startWidth = surfaceItem.width;
                startHeight = surfaceItem.height;
                leftBorder = mouseX > 0 && mouseX < root.borderThickness;
                rightBorder = mouseX > (root.width - root.borderThickness) && mouseX < root.width;
                topBorder = mouseY > 0 && mouseY < root.borderThickness;
                bottomBorder = mouseY > (root.height - root.borderThickness) && mouseY < root.height;
                dragging = true;
            } else {
                dragging = false;
            }
        }

        onMouseXChanged: {
            if (!pressed || !dragging) {
                return;
            }

            var pos = mapToItem(root.parent, mouseX, mouseY);

            var deltaX = pos.x - startX;
            if (leftBorder) {
                if (startWidth - deltaX >= root.minWidth) {
                    surfaceItem.surfaceWidth = startWidth - deltaX;
                } else {
                    surfaceItem.surfaceWidth = root.minWidth;
                }
            } else if (rightBorder) {
                if (startWidth + deltaX >= root.minWidth) {
                    surfaceItem.surfaceWidth = startWidth + deltaX;
                } else {
                    surfaceItem.surfaceWidth = root.minWidth;
                }
            }
        }

        onMouseYChanged: {
            if (!pressed || !dragging) {
                return;
            }

            var pos = mapToItem(root.parent, mouseX, mouseY);

            var deltaY = pos.y - startY;
            if (topBorder) {
                if (startHeight - deltaY >= root.minHeight) {
                    surfaceItem.surfaceHeight = startHeight - deltaY;
                } else {
                    surfaceItem.surfaceHeight = root.minHeight;
                }
            } else if (bottomBorder) {
                if (startHeight + deltaY >= root.minHeight) {
                    surfaceItem.surfaceHeight = startHeight + deltaY;
                } else {
                    surfaceItem.surfaceHeight = root.minHeight;
                }
            }
        }
    }

    TitleBar {
        id: titleBar
        anchors.left: parent.left
        anchors.leftMargin: root.borderThickness
        anchors.right: parent.right
        anchors.rightMargin: root.borderThickness
        anchors.top: parent.top
        anchors.topMargin: root.borderThickness

        target: root
        cloned: root.cloned
        onCloneRequested: { root.cloneRequested(); }
    }

    MirSurfaceItem {
        id: surfaceItem

        width: surface ? surface.size.width : 50
        height: surface ? surface.size.height : 50

        onWidthChanged: {
            if (resizeArea.dragging && resizeArea.leftBorder) {
                root.x = resizeArea.startX + resizeArea.startWidth - surfaceItem.width;
            }
        }

        onHeightChanged: {
            if (resizeArea.dragging && resizeArea.topBorder) {
                root.y = resizeArea.startY + resizeArea.startHeight - surfaceItem.height;
            }
        }

        anchors.top: titleBar.bottom
        anchors.left: parent.left
        anchors.leftMargin: root.borderThickness

        consumesInput: true
    }
}