~unity-team/+junk/dashboard-playground

« back to all changes in this revision

Viewing changes to Dash/Dash.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
import Utils 0.1
 
21
import "../Components"
 
22
 
 
23
Showable {
 
24
    id: dash
 
25
 
 
26
    property alias contentProgress: dashContent.contentProgress
 
27
    property string showLensOnLoaded: "home.lens"
 
28
    property real contentScale: 1.0
 
29
 
 
30
    width: units.gu(40)
 
31
    height: units.gu(71)
 
32
 
 
33
    function setCurrentLens(lensId, animate, reset) {
 
34
        var lensIndex = filteredLenses.findFirst(Lenses.RoleId, lensId)
 
35
 
 
36
        if (lensIndex == -1) {
 
37
            console.warn("No match for lens with id: %1".arg(lensId))
 
38
            return
 
39
        }
 
40
 
 
41
        if (lensIndex == dashContent.currentIndex && !reset) {
 
42
            // the lens is already the current one
 
43
            return
 
44
        }
 
45
 
 
46
        dashContent.setCurrentLensAtIndex(lensIndex, animate, reset)
 
47
    }
 
48
 
 
49
    SortFilterProxyModel {
 
50
        id: filteredLenses
 
51
        model: Lenses {
 
52
            id: lenses
 
53
        }
 
54
        dynamicSortFilter: true
 
55
 
 
56
        filterRole: Lenses.RoleVisible
 
57
        filterRegExp: RegExp("^true$")
 
58
    }
 
59
 
 
60
    DashContent {
 
61
        id: dashContent
 
62
        anchors.fill: parent
 
63
        model: filteredLenses
 
64
        lenses: lenses
 
65
        onMovementStarted: dashbar.startNavigation()
 
66
        onMovementEnded: dashbar.stopNavigation()
 
67
        onContentFlickStarted: dashbar.finishNavigation()
 
68
        onContentEndReached: dashbar.finishNavigation()
 
69
        onPreviewShown: dashbar.finishNavigation()
 
70
        onLensLoaded: {
 
71
            if (lensId == dash.showLensOnLoaded) {
 
72
                dash.setCurrentLens(lensId, false, false)
 
73
                dash.showLensOnLoaded = ""
 
74
            }
 
75
        }
 
76
        scale: dash.contentScale
 
77
        clip: scale != 1.0
 
78
    }
 
79
 
 
80
    DashBar {
 
81
        id: dashbar
 
82
        anchors.bottom: parent.bottom
 
83
        anchors.left: parent.left
 
84
        anchors.right: parent.right
 
85
        model: filteredLenses
 
86
        currentIndex: dashContent.currentIndex
 
87
        onItemSelected: dashContent.setCurrentLensAtIndex(index, true, false)
 
88
        opacity: dash.contentScale == 1.0 ? 1.0 : 0.0
 
89
        Behavior on opacity { NumberAnimation { easing.type: Easing.OutQuad; duration: 150 } }
 
90
    }
 
91
}