~mterry/+junk/u8

« back to all changes in this revision

Viewing changes to qml/Stage/WindowDecoration.qml

Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 */
16
16
 
17
17
import QtQuick 2.4
18
 
import Unity.Application 0.1 // For Mir singleton
19
18
import Ubuntu.Components 1.3
20
19
import "../Components"
21
 
import "../Components/PanelState"
22
20
 
23
21
MouseArea {
24
22
    id: root
25
23
    clip: true
26
24
 
27
 
    property Item target
 
25
    property Item target // appDelegate
28
26
    property alias title: titleLabel.text
 
27
    property alias maximizeButtonShown: buttons.maximizeButtonShown
29
28
    property bool active: false
 
29
    property alias overlayShown: buttons.overlayShown
 
30
 
 
31
    readonly property real buttonsWidth: buttons.width + row.spacing
 
32
 
 
33
    acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
30
34
    hoverEnabled: true
31
35
 
32
36
    signal closeClicked()
35
39
    signal maximizeHorizontallyClicked()
36
40
    signal maximizeVerticallyClicked()
37
41
 
38
 
    onDoubleClicked: root.maximizeClicked()
39
 
 
40
 
    QtObject {
41
 
        id: priv
42
 
        property real distanceX
43
 
        property real distanceY
44
 
        property bool dragging
45
 
    }
46
 
 
47
 
    onPressedChanged: {
48
 
        if (pressed) {
49
 
            var pos = mapToItem(root.target, mouseX, mouseY);
50
 
            priv.distanceX = pos.x;
51
 
            priv.distanceY = pos.y;
52
 
            priv.dragging = true;
53
 
        } else {
54
 
            priv.dragging = false;
55
 
            Mir.cursorName = "";
56
 
        }
57
 
    }
58
 
 
59
 
    onPositionChanged: {
60
 
        if (priv.dragging) {
61
 
            Mir.cursorName = "grabbing";
62
 
            var pos = mapToItem(root.target.parent, mouseX, mouseY);
63
 
            root.target.x = pos.x - priv.distanceX;
64
 
            root.target.y = Math.max(pos.y - priv.distanceY, PanelState.panelHeight);
65
 
        }
66
 
    }
 
42
    onDoubleClicked: {
 
43
        if (target.canBeMaximized && mouse.button == Qt.LeftButton) {
 
44
            root.maximizeClicked();
 
45
        }
 
46
    }
 
47
 
 
48
    // do not let unhandled wheel event pass thru the decoration
 
49
    onWheel: wheel.accepted = true;
67
50
 
68
51
    Rectangle {
69
52
        anchors.fill: parent
73
56
    }
74
57
 
75
58
    Row {
 
59
        id: row
76
60
        anchors {
77
61
            fill: parent
78
 
            leftMargin: units.gu(1)
 
62
            leftMargin: overlayShown ? units.gu(5) : units.gu(1)
79
63
            rightMargin: units.gu(1)
80
64
            topMargin: units.gu(0.5)
81
65
            bottomMargin: units.gu(0.5)
82
66
        }
 
67
        Behavior on anchors.leftMargin {
 
68
            UbuntuNumberAnimation {}
 
69
        }
 
70
 
83
71
        spacing: units.gu(3)
84
72
 
85
73
        WindowControlButtons {
89
77
            onCloseClicked: root.closeClicked();
90
78
            onMinimizeClicked: root.minimizeClicked();
91
79
            onMaximizeClicked: root.maximizeClicked();
92
 
            onMaximizeHorizontallyClicked: root.maximizeHorizontallyClicked();
93
 
            onMaximizeVerticallyClicked: root.maximizeVerticallyClicked();
94
 
            closeButtonShown: root.target.application.appId !== "unity8-dash"
 
80
            onMaximizeHorizontallyClicked: if (root.target.canBeMaximizedHorizontally) root.maximizeHorizontallyClicked();
 
81
            onMaximizeVerticallyClicked: if (root.target.canBeMaximizedVertically) root.maximizeVerticallyClicked();
 
82
            closeButtonShown: root.target.appId !== "unity8-dash"
95
83
        }
96
84
 
97
85
        Label {
104
92
            fontSize: "medium"
105
93
            font.weight: root.active ? Font.Light : Font.Medium
106
94
            elide: Text.ElideRight
 
95
            opacity: overlayShown ? 0 : 1
 
96
            visible: opacity != 0
 
97
            Behavior on opacity { UbuntuNumberAnimation {} }
107
98
        }
108
99
    }
109
100
}