~ubuntu-branches/ubuntu/trusty/unity8/trusty-proposed

« back to all changes in this revision

Viewing changes to qml/Panel/Indicators/DefaultIndicatorPage.qml

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2014-02-03 16:56:47 UTC
  • mfrom: (1.1.64)
  • Revision ID: package-import@ubuntu.com-20140203165647-ik9w833cac4zu9da
Tags: 7.84+14.04.20140130.is.7.84+14.04.20131220-0ubuntu1
Reverting to last known good version, as after installing a click
application, it redirects you to the first click application everytime.
(LP: #1275832)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
15
 *
16
16
 * Authors:
17
 
 *      Renato Araujo Oliveira Filho <renato@canonical.com>
18
17
 *      Nick Dedekind <nick.dedekind@canonical.com>
19
18
 */
20
19
 
21
20
import QtQuick 2.0
22
 
import Ubuntu.Components 0.1 as Components
23
21
import Unity.Indicators 0.1 as Indicators
24
22
 
25
 
Indicators.IndicatorBase {
26
 
    id: main
27
 
 
28
 
    //const
29
 
    property bool contentActive: false
30
 
    property string title: rootActionState.title
31
 
    property alias emptyText: emptyLabel.text
32
 
    property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
33
 
 
34
 
    Indicators.UnityMenuModelStack {
35
 
        id: menuStack
36
 
        head: contentActive ? main.menuModel : null
37
 
 
38
 
        property var rootMenu: null
39
 
 
40
 
        onTailChanged: {
41
 
            if (!tail) {
42
 
                rootMenu = null;
43
 
            } else if (rootMenu != tail) {
44
 
                if (tail.get(0, "type") === rootMenuType) {
45
 
                    rootMenu = menuStack.tail.submenu(0);
46
 
                    push(rootMenu, 0);
47
 
                } else {
48
 
                    rootMenu = null;
49
 
                }
50
 
            }
51
 
        }
52
 
    }
53
 
 
54
 
    Connections {
55
 
        target: menuStack.tail
56
 
        onRowsInserted: {
57
 
            if (menuStack.rootMenu !== menuStack.tail && menuStack.tail.get(0, "type") === rootMenuType) {
58
 
                menuStack.rootMenu = menuStack.tail.submenu(0);
59
 
                menuStack.push(menuStack.rootMenu, 0);
60
 
            }
61
 
        }
62
 
        onModelReset: {
63
 
            if (menuStack.rootMenu !== menuStack.tail && menuStack.tail.get(0, "type") === rootMenuType) {
64
 
                menuStack.rootMenu = menuStack.tail.submenu(0);
65
 
                menuStack.push(menuStack.rootMenu, 0);
66
 
            }
67
 
        }
68
 
    }
69
 
 
70
 
    ListView {
71
 
        id: mainMenu
72
 
        objectName: "mainMenu"
73
 
        model: menuStack.rootMenu
74
 
 
75
 
        anchors {
76
 
            fill: parent
77
 
            bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
78
 
 
79
 
            Behavior on bottomMargin {
80
 
                NumberAnimation {
81
 
                    duration: 175
82
 
                    easing.type: Easing.OutQuad
83
 
                }
84
 
            }
85
 
            // TODO - does ever frame.
86
 
            onBottomMarginChanged: {
87
 
                mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
88
 
            }
89
 
        }
90
 
 
91
 
        // Ensure all delegates are cached in order to improve smoothness of scrolling
92
 
        cacheBuffer: 10000
93
 
 
94
 
        // Only allow flicking if the content doesn't fit on the page
95
 
        interactive: contentHeight > height
96
 
 
97
 
        property int selectedIndex: -1
98
 
        property bool blockCurrentIndexChange: false
99
 
        // for count = 0
100
 
        onCountChanged: {
101
 
            if (count == 0 && selectedIndex != -1) {
102
 
                selectedIndex = -1;
103
 
            }
104
 
        }
105
 
        // for highlight following
106
 
        onSelectedIndexChanged: {
107
 
            if (currentIndex != selectedIndex) {
108
 
                var blocked = blockCurrentIndexChange;
109
 
                blockCurrentIndexChange = true;
110
 
 
111
 
                currentIndex = selectedIndex;
112
 
 
113
 
                blockCurrentIndexChange = blocked;
114
 
            }
115
 
        }
116
 
        // for item addition/removal
117
 
        onCurrentIndexChanged: {
118
 
            if (!blockCurrentIndexChange) {
119
 
                if (selectedIndex != -1 && selectedIndex != currentIndex) {
120
 
                    selectedIndex = currentIndex;
121
 
                }
122
 
            }
123
 
        }
124
 
 
125
 
        delegate: Loader {
126
 
            id: loader
127
 
            objectName: "menuItem" + index
128
 
            asynchronous: false
129
 
            visible: height > 0
130
 
 
131
 
            property int modelIndex: index
132
 
 
133
 
            anchors {
134
 
                left: parent.left
135
 
                right: parent.right
136
 
            }
137
 
 
138
 
            sourceComponent: factory.load(model)
139
 
 
140
 
            onLoaded: {
141
 
                if (item.hasOwnProperty("selected")) {
142
 
                    item.selected = mainMenu.selectedIndex == index;
143
 
                }
144
 
                if (item.hasOwnProperty("menuSelected")) {
145
 
                    item.menuSelected.connect(function() { mainMenu.selectedIndex = index; });
146
 
                }
147
 
                if (item.hasOwnProperty("menuDeselected")) {
148
 
                    item.menuDeselected.connect(function() { mainMenu.selectedIndex = -1; });
149
 
                }
150
 
                if (item.hasOwnProperty("menuData")) {
151
 
                    item.menuData = Qt.binding(function() { return model; });
152
 
                }
153
 
                if (item.hasOwnProperty("menuIndex")) {
154
 
                    item.menuIndex = Qt.binding(function() { return modelIndex; });
155
 
                }
156
 
            }
157
 
 
158
 
            Binding {
159
 
                target: item ? item : null
160
 
                property: "objectName"
161
 
                value: model.action
162
 
            }
163
 
 
164
 
            // TODO: Fixes lp#1243146
165
 
            // This is a workaround for a Qt bug. https://bugreports.qt-project.org/browse/QTBUG-34351
166
 
            Connections {
167
 
                target: mainMenu
168
 
                onSelectedIndexChanged: {
169
 
                    if (loader.item && loader.item.hasOwnProperty("selected")) {
170
 
                        loader.item.selected = mainMenu.selectedIndex == index;
171
 
                    }
172
 
                }
173
 
            }
174
 
        }
175
 
    }
176
 
 
177
 
    Indicators.MenuItemFactory {
178
 
        id: factory
179
 
        menuModel: mainMenu.model ? mainMenu.model : null
180
 
    }
181
 
 
182
 
    Components.Label {
183
 
        id: emptyLabel
184
 
        objectName: "emptyLabel"
185
 
        visible: mainMenu.count == 0
186
 
        anchors {
187
 
            top: parent.top
188
 
            left: parent.left
189
 
            right: parent.right
190
 
            topMargin: units.gu(2)
191
 
        }
192
 
        wrapMode: Text.WordWrap
193
 
        horizontalAlignment: Text.AlignHCenter
194
 
 
195
 
        //style
196
 
        color: "#e8e1d0"
197
 
        fontSize: "medium"
198
 
 
199
 
        text: "Empty!"
200
 
    }
201
 
 
202
 
    function start()
203
 
    {
204
 
        reset()
205
 
        if (!contentActive) {
206
 
            contentActive = true;
207
 
        }
208
 
    }
209
 
 
210
 
    function stop()
211
 
    {
212
 
        if (contentActive) {
213
 
            contentActive = false;
214
 
        }
215
 
    }
216
 
 
217
 
    function reset()
218
 
    {
219
 
        mainMenu.selectedIndex = -1;
220
 
        mainMenu.positionViewAtBeginning();
221
 
    }
 
23
Indicators.IndicatorPage {
 
24
      anchors.fill: parent
222
25
}