~ci-train-bot/unity8/unity8-ubuntu-zesty-2167

« back to all changes in this revision

Viewing changes to Dash/DashBar.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 Ubuntu.Components 0.1
 
19
import Unity 0.1
 
20
 
 
21
Item {
 
22
    id: dashBar
 
23
 
 
24
    property var model
 
25
    property alias currentIndex: row.currentIndex
 
26
 
 
27
    property int lineHeight: units.dp(2)
 
28
    property int itemSize: units.gu(7)
 
29
    property int iconSize: units.gu(2.5)
 
30
 
 
31
    signal itemSelected(int index)
 
32
 
 
33
    width: units.gu(40)
 
34
    height: units.gu(6)
 
35
 
 
36
    function startNavigation() {
 
37
        timeout.stop()
 
38
        panel.opened = true
 
39
    }
 
40
 
 
41
    function stopNavigation() {
 
42
        timeout.restart()
 
43
    }
 
44
 
 
45
    function finishNavigation() {
 
46
        panel.opened = false
 
47
    }
 
48
 
 
49
    Timer {
 
50
        id: timeout
 
51
        interval: 1500
 
52
        running: false
 
53
        repeat: false
 
54
        onTriggered: finishNavigation()
 
55
    }
 
56
 
 
57
    Panel {
 
58
        id: panel
 
59
        objectName: "panel"
 
60
        anchors.fill: parent
 
61
 
 
62
        locked: true // TODO: remove this when lp bug #1179569 will be fixed
 
63
 
 
64
        Rectangle {
 
65
            color: "black"
 
66
            anchors.fill: parent
 
67
 
 
68
            ListView {
 
69
                id: row
 
70
                objectName: "row"
 
71
                model: dashBar.model
 
72
                orientation: ListView.Horizontal
 
73
                width: Math.min(Math.max(dashBar.width/2, units.gu(40)), count * itemSize)
 
74
                height: parent.height
 
75
                anchors.horizontalCenter: parent.horizontalCenter
 
76
                onMovingChanged: if (moving) { timeout.stop() } else { timeout.restart() }
 
77
                interactive: visibleArea.widthRatio < 1 && panel.opened
 
78
                highlightFollowsCurrentItem: false
 
79
 
 
80
                onCurrentItemChanged: {
 
81
                    highlightLine.width = currentItem.width
 
82
                    highlightLine.x = x + currentItem.x
 
83
                }
 
84
 
 
85
                delegate:
 
86
                    Item {
 
87
                        signal clicked()
 
88
 
 
89
                        width: itemSize
 
90
                        height: dashBar.height
 
91
                        anchors.top: parent.top
 
92
 
 
93
                        onClicked: {
 
94
                            dashBar.itemSelected(index)
 
95
                            timeout.restart()
 
96
                        }
 
97
 
 
98
                        Image {
 
99
                            anchors.centerIn: parent
 
100
                            /* FIXME: should be 'source: lens.iconHint' but the
 
101
                               lenses do not contain the right icons yet
 
102
                            */
 
103
                            source: "graphics/lensIcons/%1.png".arg(lens.name)
 
104
                            height: iconSize
 
105
                            width: iconSize
 
106
                            // opacity: index == currentIndex ? 1 : 1 // same opacity for now
 
107
                            smooth: true
 
108
                        }
 
109
                    }
 
110
            }
 
111
        }
 
112
    }
 
113
 
 
114
    Rectangle {
 
115
        anchors {
 
116
            left: parent.left
 
117
            right: parent.right
 
118
            bottom: parent.bottom
 
119
        }
 
120
        height: dashBar.lineHeight
 
121
        color: "black"
 
122
 
 
123
        Rectangle {
 
124
            id: highlightLine
 
125
            color: "#dd4814"
 
126
            height: parent.height
 
127
            anchors.bottom: parent.bottom
 
128
            z: 1
 
129
 
 
130
            Behavior on x {NumberAnimation { duration: 150; easing.type: Easing.OutCubic}}
 
131
            Behavior on width {NumberAnimation { duration: 150; easing.type: Easing.OutCubic}}
 
132
        }
 
133
    }
 
134
}