~vanvugt/qtmir/supersmooth2

« back to all changes in this revision

Viewing changes to demos/qml-demo-shell/TitleBar.qml

  • Committer: CI Train Bot
  • Author(s): Daniel d'Andrada
  • Date: 2015-08-27 13:58:46 UTC
  • mfrom: (363.2.6 mirSurface)
  • Revision ID: ci-train-bot@canonical.com-20150827135846-ozjrdoghb3k35q7d
Enable multiple MirSurfaceItems rendering the same MirSurface

So MirSurface is the model and MirSurfaceItem is the view+controller.

+ Make MirSurfaceItem instantiable from QML
+ Isolate all mir::scene::Surface code inside MirSurface
+ Enhanced qml-demo-shell: you can now move, resize and *clone* windows
Approved by: Gerry Boland

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
 
 
3
Rectangle {
 
4
    id: root
 
5
    color: "brown"
 
6
    height: 25
 
7
 
 
8
    property Item target
 
9
    property bool cloned: false
 
10
    property bool closeRequested: false
 
11
    signal cloneRequested()
 
12
 
 
13
    MouseArea {
 
14
        anchors.fill: parent
 
15
        property real distanceX
 
16
        property real distanceY
 
17
        property bool dragging
 
18
        onPressedChanged: {
 
19
            if (pressed) {
 
20
                var pos = mapToItem(root.target, mouseX, mouseY);
 
21
                distanceX = pos.x;
 
22
                distanceY = pos.y;
 
23
                dragging = true;
 
24
            } else {
 
25
                dragging = false;
 
26
            }
 
27
        }
 
28
        onMouseXChanged: {
 
29
            if (dragging) {
 
30
                var pos = mapToItem(root.target.parent, mouseX, mouseY);
 
31
                root.target.x = pos.x - distanceX;
 
32
                root.target.y = pos.y - distanceY;
 
33
            }
 
34
        }
 
35
    }
 
36
 
 
37
    Text {
 
38
        visible: !root.cloned
 
39
        anchors.top: parent.top
 
40
        anchors.bottom: parent.bottom
 
41
        text: "CLONE"
 
42
        MouseArea {
 
43
            anchors.fill: parent
 
44
            onClicked: {
 
45
                root.cloneRequested();
 
46
            }
 
47
        }
 
48
    }
 
49
 
 
50
    Text {
 
51
        anchors.top: parent.top
 
52
        anchors.bottom: parent.bottom
 
53
        anchors.right: parent.right
 
54
        width: contentWidth
 
55
        text: "X"
 
56
        fontSizeMode: Text.VerticalFit
 
57
        minimumPixelSize: 10; font.pixelSize: 72
 
58
        font.weight: Font.Bold
 
59
        horizontalAlignment: Text.AlignRight
 
60
        verticalAlignment: Text.AlignVCenter
 
61
        MouseArea {
 
62
            anchors.fill: parent
 
63
            onClicked: {
 
64
                root.closeRequested = true;
 
65
            }
 
66
        }
 
67
    }
 
68
}
 
69