~gerboland/unity/8-refactor-wm-and-test

« back to all changes in this revision

Viewing changes to Bottombar/Bottombar.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import "../Components"
 
19
import "../Components/Math.js" as MathLocal
 
20
import Unity 0.1
 
21
 
 
22
Item {
 
23
    id: bottombar
 
24
    width: shell.width
 
25
    height: shell.height
 
26
 
 
27
    property variant theHud
 
28
    property bool enabled: false
 
29
    readonly property real bottomEdgeButtonCenterDistance: units.gu(34)
 
30
    readonly property real bottomEdgeShowButtonDistance: units.gu(2)
 
31
 
 
32
    property bool __applicationInFocus: false
 
33
 
 
34
    state: "hidden"
 
35
 
 
36
    HudButton {
 
37
        id: hudButton
 
38
 
 
39
        x: MathLocal.clamp(hudButtonRevealer.pressedX - width / 2, 0, bottombar.width - width)
 
40
        y: bottombar.height - bottomEdgeButtonCenterDistance - height / 2 - bottomMargin
 
41
        Behavior on bottomMargin {
 
42
            NumberAnimation{duration: hudButton.opacity < 0.01 ? 200 : 70; easing.type: Easing.OutQuart}
 
43
        }
 
44
        mouse: {
 
45
            if (hudButtonRevealer.draggingArea.pressed) {
 
46
                var mapped = mapFromItem(hudButtonRevealer.draggingArea, hudButtonRevealer.draggingArea.mouseX, hudButtonRevealer.draggingArea.mouseY)
 
47
                return Qt.point(mapped.x, mapped.y)
 
48
            } else {
 
49
                return mouse
 
50
            }
 
51
        }
 
52
 
 
53
        Behavior on opacity {
 
54
            NumberAnimation{ duration: 200; easing.type: Easing.OutCubic}
 
55
        }
 
56
    }
 
57
 
 
58
    Connections {
 
59
        target: theHud
 
60
        onShownChanged: bottomBarVisibilityCommunicatorShell.forceHidden = theHud.shown
 
61
    }
 
62
 
 
63
    function updateApplicationInFocus() {
 
64
        if (shell.applicationManager.mainStageFocusedApplication || shell.applicationManager.sideStageFocusedApplication) {
 
65
            __applicationInFocus = true
 
66
        } else {
 
67
            __applicationInFocus = false
 
68
        }
 
69
    }
 
70
 
 
71
    Connections {
 
72
        target: shell.applicationManager
 
73
        ignoreUnknownSignals: true
 
74
        onMainStageFocusedApplicationChanged: updateApplicationInFocus()
 
75
        onSideStageFocusedApplicationChanged: updateApplicationInFocus()
 
76
    }
 
77
 
 
78
    Showable {
 
79
        id: hudButtonShowable
 
80
 
 
81
        opacity: 1.0
 
82
        width: parent.width
 
83
        height: bottomEdgeShowButtonDistance
 
84
        shown: false
 
85
        showAnimation: StandardAnimation { property: "y"; duration: 350; to: hudButtonRevealer.openedValue; easing.type: Easing.OutCubic }
 
86
        hideAnimation: StandardAnimation { property: "y"; duration: 350; to: hudButtonRevealer.closedValue; easing.type: Easing.OutCubic }
 
87
        onYChanged: {
 
88
            if (y == hudButtonRevealer.openedValue)
 
89
                bottombar.state = "shown"
 
90
        }
 
91
 
 
92
        // eater
 
93
        MouseArea {
 
94
            anchors.fill: parent
 
95
        }
 
96
    }
 
97
 
 
98
    Revealer {
 
99
        id: hudButtonRevealer
 
100
 
 
101
        property double pressedX
 
102
 
 
103
        enabled: !theHud.shown && bottombar.enabled && __applicationInFocus
 
104
        direction: Qt.RightToLeft
 
105
        openedValue: bottombar.height - height
 
106
        closedValue: bottombar.height
 
107
        target: hudButtonShowable
 
108
        width: hudButtonShowable.width
 
109
        height: hudButtonShowable.height
 
110
        anchors.bottom: bottombar.bottom
 
111
        onOpenPressed: {
 
112
            pressedX = mouseX
 
113
        }
 
114
 
 
115
        onOpenReleased: {
 
116
            if (hudButton.opacity != 0 && hudButton.mouseOver) {
 
117
                hudButtonShowable.hide()
 
118
                theHud.show()
 
119
            } else {
 
120
                hudButtonShowable.hide()
 
121
            }
 
122
        }
 
123
    }
 
124
 
 
125
    Connections {
 
126
        target: hudButtonShowable.hideAnimation
 
127
        onRunningChanged: {
 
128
            if (hudButtonShowable.hideAnimation.running) {
 
129
                bottombar.state = "hidden"
 
130
            }
 
131
        }
 
132
    }
 
133
 
 
134
    states: [
 
135
        State {
 
136
            name: "hidden"
 
137
            PropertyChanges { target: hudButton; opacity: 0}
 
138
            PropertyChanges { target: hudButton; bottomMargin: units.gu(-1)}
 
139
        },
 
140
        State {
 
141
            name: "shown"
 
142
            PropertyChanges { target: hudButton; opacity: 1}
 
143
            PropertyChanges { target: hudButton; bottomMargin: units.gu(0)}
 
144
        }
 
145
    ]
 
146
 
 
147
}