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

« back to all changes in this revision

Viewing changes to Panel/IndicatorRow.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
 
 
20
Item {
 
21
    id: indicatorRow
 
22
 
 
23
    property QtObject currentItem : null
 
24
    property int currentItemIndex: currentItem ? currentItem.ownIndex : -1
 
25
    property alias row: row
 
26
    property QtObject indicatorsModel: null
 
27
    property bool overviewActive: false // "state of the menu"
 
28
 
 
29
    Behavior on y {NumberAnimation {duration: 300; easing.type: Easing.OutCubic} }
 
30
 
 
31
    width: units.gu(40)
 
32
    height: units.gu(3)
 
33
 
 
34
    Component.onCompleted: setDefaultItem()
 
35
 
 
36
    function setDefaultItem() {
 
37
        // The leftmost indicator
 
38
        var defaultItemIndex = 0
 
39
        setItem(defaultItemIndex)
 
40
    }
 
41
 
 
42
    function setItem(index) {
 
43
        currentItem = rowRepeater.itemAt(index)
 
44
    }
 
45
 
 
46
    Row {
 
47
        id: row
 
48
 
 
49
        width: children.width
 
50
        height: parent.height
 
51
        anchors.right: parent.right
 
52
 
 
53
        Repeater {
 
54
            id: rowRepeater
 
55
            objectName: "rowRepeater"
 
56
            model: indicatorsModel ? indicatorsModel : undefined
 
57
            IndicatorItem {
 
58
               id: indicatorItem
 
59
 
 
60
               property int ownIndex: index
 
61
 
 
62
               label: model.label
 
63
               iconSource: model.iconSource
 
64
               highlighted: indicatorRow.state == "reveal" || indicatorRow.state == "locked" || indicatorRow.state == "commit" ? ownIndex == indicatorRow.currentItemIndex : false
 
65
               dimmed: { //See FIXME in Indicators regarding the "states" change
 
66
                   if (indicatorRow.state == "initial" || indicatorRow.state == "") {
 
67
                       return false;
 
68
                   } else if (indicatorRow.state == "hint") {
 
69
                       return true
 
70
                   } else {
 
71
                       return ownIndex != indicatorRow.currentItemIndex
 
72
                   }
 
73
               }
 
74
               height: indicatorRow.height
 
75
               y: {
 
76
                   //FIXME: all indicators will be initial for now.
 
77
                   if (!highlighted && !overviewActive && (indicatorRow.state == "locked" || indicatorRow.state == "commit")) {
 
78
                       return -indicatorRow.height
 
79
                   } else {
 
80
                       return 0
 
81
                   }
 
82
               }
 
83
               Behavior on y {
 
84
                    NumberAnimation{
 
85
                        duration: {
 
86
                            if (index == 0) {
 
87
                                return 250
 
88
                            } else if (index == 1) {
 
89
                                return 150
 
90
                            } else if (index == 2) {
 
91
                                return 550
 
92
                            } else if (index == 3) {
 
93
                                return 400
 
94
                            } else {
 
95
                                return 100 + Math.random() * 200
 
96
                            }
 
97
                        }
 
98
                        easing.type: Easing.OutCubic
 
99
                    }
 
100
                }
 
101
            }
 
102
        }
 
103
    }
 
104
}