~evfool/software-center/fixnavigation

« back to all changes in this revision

Viewing changes to softwarecenter/ui/qml/BreadCrumbs.qml

  • Committer: Michael Vogt
  • Date: 2011-06-16 07:42:55 UTC
  • mfrom: (1773.3.50 qml)
  • Revision ID: michael.vogt@ubuntu.com-20110616074255-sdkl5j08ixon62q8
merged lp:~osomon/software-center/qml (woah!)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2011 Canonical Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Olivier Tilloy <olivier@tilloy.net>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; version 3.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
import QtQuick 1.0
 
21
 
 
22
Item {
 
23
    id: breadcrumbs
 
24
 
 
25
    property int animationDuration: 150
 
26
    property alias model: crumbslist.model
 
27
    property alias count: crumbslist.count
 
28
 
 
29
    function addCrumb(text, view, key) {
 
30
        crumbslist.model.append({ label: text, view: view, key: key })
 
31
    }
 
32
 
 
33
    function removeCrumb() {
 
34
        if (crumbslist.model.count > 1) {
 
35
            crumbslist.model.remove(crumbslist.model.count - 1)
 
36
        }
 
37
    }
 
38
 
 
39
    signal crumbClicked(int index)
 
40
 
 
41
    SystemPalette { id: activePalette }
 
42
 
 
43
    ListView {
 
44
        id: crumbslist
 
45
        interactive: false
 
46
        anchors.fill: parent
 
47
        anchors.margins: 10
 
48
 
 
49
        model: ListModel {}
 
50
 
 
51
        orientation: ListView.Horizontal
 
52
 
 
53
        delegate: Rectangle {
 
54
            id: delegate
 
55
 
 
56
            property real margins: 10
 
57
            property real fullWidth: text.paintedWidth + 2 * margins
 
58
 
 
59
            width: fullWidth
 
60
            height: crumbslist.height
 
61
 
 
62
            border.width: 1
 
63
            border.color: activePalette.shadow
 
64
            color: mousearea.containsMouse && !mousearea.pressed ? activePalette.light : activePalette.button
 
65
 
 
66
            clip: true
 
67
 
 
68
            Text {
 
69
                id: text
 
70
                anchors.verticalCenter: parent.verticalCenter
 
71
                x: parent.margins
 
72
                color: activePalette.buttonText
 
73
                text: label
 
74
            }
 
75
 
 
76
            MouseArea {
 
77
                id: mousearea
 
78
                anchors.fill: parent
 
79
                hoverEnabled: true
 
80
                onClicked: {
 
81
                    while ((crumbslist.model.count - 1) > index) {
 
82
                        breadcrumbs.removeCrumb()
 
83
                    }
 
84
                    breadcrumbs.crumbClicked(index)
 
85
                }
 
86
            }
 
87
 
 
88
            ListView.onAdd: SequentialAnimation {
 
89
                PropertyAction { target: delegate; property: "ListView.delayRemove"; value: true }
 
90
                PropertyAction { target: delegate; property: "width"; value: 0 }
 
91
                NumberAnimation { target: delegate; property: "width"; to: fullWidth; duration: breadcrumbs.animationDuration }
 
92
                PropertyAction { target: delegate; property: "ListView.delayRemove"; value: false }
 
93
            }
 
94
            ListView.onRemove: SequentialAnimation {
 
95
                PropertyAction { target: delegate; property: "ListView.delayRemove"; value: true }
 
96
                NumberAnimation { target: delegate; property: "width"; to: 0; duration: breadcrumbs.animationDuration }
 
97
                PropertyAction { target: delegate; property: "ListView.delayRemove"; value: false }
 
98
            }
 
99
        }
 
100
    }
 
101
}
 
102