~alan-griffiths/miral/fix-1645284

« back to all changes in this revision

Viewing changes to miral-qt/demos/qml-demo-shell/windowModel.qml

  • Committer: Alan Griffiths
  • Date: 2016-11-07 17:59:19 UTC
  • mfrom: (436.1.1 miral2)
  • Revision ID: alan@octopull.co.uk-20161107175919-stbb64i7j1htgog2
[miral-qt] delete all as qtmir work on MirAL has shifted to lp:~unity-team/qtmir/miral-qt-integration and this is a needless distration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import QtQuick 2.4
2
 
import Unity.Application 0.1
3
 
import Mir.Pointer 0.1
4
 
 
5
 
FocusScope {
6
 
    id: root
7
 
    focus: true
8
 
 
9
 
    WindowModel {
10
 
        id: windowModel;
11
 
    }
12
 
 
13
 
    Item {
14
 
        id: windowViewContainer
15
 
        anchors.fill: parent
16
 
 
17
 
        Repeater {
18
 
            model: windowModel
19
 
 
20
 
            delegate: MirSurfaceItem {
21
 
                id: surfaceItem
22
 
                surface: model.surface
23
 
                consumesInput: true // QUESTION: why is this non-default?
24
 
                x: surface.position.x
25
 
                y: surface.position.y
26
 
                width: surface.size.width
27
 
                height: surface.size.height
28
 
                focus: surface.focused
29
 
                visible: surface.visible
30
 
 
31
 
                Rectangle {
32
 
                    anchors { top: parent.bottom; right: parent.right }
33
 
                    width: childrenRect.width
34
 
                    height: childrenRect.height
35
 
                    color: surface.focused ? "red" : "lightsteelblue"
36
 
                    opacity: 0.8
37
 
                    Text {
38
 
                        text: surface.position.x + "," + surface.position.y + " " + surface.size.width + "x" + surface.size.height
39
 
                        font.pixelSize: 10
40
 
                    }
41
 
                }
42
 
 
43
 
                Rectangle { anchors.fill: parent; z: -1; color: "black"; opacity: 0.3 }
44
 
            }
45
 
        }
46
 
    }
47
 
 
48
 
    Button {
49
 
        anchors { right: parent.right; top: parent.top }
50
 
        height: 30
51
 
        width: 80
52
 
        text: "Quit"
53
 
        onClicked: Qt.quit()
54
 
    }
55
 
 
56
 
    WindowModelDebugView {
57
 
        anchors { right: parent.right; bottom: parent.bottom }
58
 
        model: windowModel
59
 
    }
60
 
 
61
 
    Text {
62
 
        anchors { left: parent.left; bottom: parent.bottom }
63
 
        text: "Move window: Ctrl+click\n
64
 
Resize window: Ctrl+Right click"
65
 
    }
66
 
 
67
 
    Rectangle {
68
 
        id: mousePointer
69
 
        color: "black"
70
 
        width: 6
71
 
        height: 10
72
 
        x: PointerPosition.x
73
 
        y: PointerPosition.y
74
 
    }
75
 
 
76
 
    MouseArea {
77
 
        anchors.fill: parent
78
 
        acceptedButtons: Qt.LeftButton | Qt.RightButton
79
 
        hoverEnabled: false
80
 
        property variant window: null
81
 
        property int initialWindowXPosition
82
 
        property int initialWindowYPosition
83
 
        property int initialWindowWidth
84
 
        property int initialWindowHeight
85
 
        property int initialMouseXPosition
86
 
        property int initialMouseYPosition
87
 
        property var action
88
 
 
89
 
        function moveWindowBy(window, delta) {
90
 
            window.surface.requestedPosition = Qt.point(initialWindowXPosition + delta.x,
91
 
                                                        initialWindowYPosition + delta.y);
92
 
        }
93
 
        function resizeWindowBy(window, delta) {
94
 
            window.surface.resize(Qt.size(initialWindowWidth + delta.x,
95
 
                                          initialWindowHeight + delta.y))
96
 
        }
97
 
 
98
 
        onPressed: {
99
 
            if (mouse.modifiers & Qt.ControlModifier) {
100
 
                window = windowViewContainer.childAt(mouse.x, mouse.y)
101
 
                if (!window) return;
102
 
 
103
 
                if (mouse.button == Qt.LeftButton) {
104
 
                    initialWindowXPosition = window.surface.position.x
105
 
                    initialWindowYPosition = window.surface.position.y
106
 
                    action = moveWindowBy
107
 
                } else if (mouse.button == Qt.RightButton) {
108
 
                    initialWindowHeight = window.surface.size.height
109
 
                    initialWindowWidth = window.surface.size.width
110
 
                    action = resizeWindowBy
111
 
                }
112
 
                initialMouseXPosition = mouse.x
113
 
                initialMouseYPosition = mouse.y
114
 
            } else {
115
 
                mouse.accepted = false
116
 
            }
117
 
        }
118
 
 
119
 
        onPositionChanged: {
120
 
            if (!window) {
121
 
                mouse.accepted = false
122
 
                return
123
 
            }
124
 
            action(window, Qt.point(mouse.x - initialMouseXPosition, mouse.y - initialMouseYPosition))
125
 
        }
126
 
 
127
 
        onReleased: {
128
 
            if (!window) {
129
 
                mouse.accepted = false
130
 
                return
131
 
            }
132
 
            action(window, Qt.point(mouse.x - initialMouseXPosition, mouse.y - initialMouseYPosition))
133
 
            window = null;
134
 
        }
135
 
    }
136
 
}