~ubuntu-branches/ubuntu/vivid/muon/vivid-proposed

« back to all changes in this revision

Viewing changes to discover/qml/Information.qml

Tags: upstream-1.3.65
ImportĀ upstreamĀ versionĀ 1.3.65

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 1.1
 
2
import org.kde.plasma.components 0.1
 
3
 
 
4
Item {
 
5
    id: viewItem
 
6
    property int current: 0
 
7
    property QtObject dataModel
 
8
    property QtObject currentElement: dataModel.get(current)
 
9
    property Component delegate
 
10
    property Item currentItem
 
11
    visible: false
 
12
    smooth: true
 
13
    
 
14
    onDelegateChanged: restoreView()
 
15
    onCurrentElementChanged: restoreView()
 
16
    onDataModelChanged: current = 0
 
17
    
 
18
    Component.onCompleted: viewItem.visible=true
 
19
    
 
20
    function restoreView() { return restoreViewInternal(!viewItem.visible); }
 
21
    function restoreViewInternal(force) {
 
22
        if(!delegate || (destroyAnimation.running && !force) || !currentElement) {
 
23
            return
 
24
        }
 
25
        
 
26
        try {
 
27
            var oldItem = viewItem.currentItem
 
28
            viewItem.currentItem = delegate.createObject(viewItem, { "modelData": currentElement })
 
29
            viewItem.currentItem.anchors.fill=viewItem
 
30
            
 
31
            if(oldItem) {
 
32
                if(force) {
 
33
                    oldItem.destroy()
 
34
                } else {
 
35
                    viewItem.currentItem.opacity = 0
 
36
                    oldItem.z = viewItem.currentItem.z+1
 
37
                    fadeoutAnimation.target = oldItem
 
38
                    fadeinAnimation.target = viewItem.currentItem
 
39
                    destroyAnimation.start()
 
40
                }
 
41
            }
 
42
        } catch (e) {
 
43
            console.log("error: "+e)
 
44
            console.log("comp error: "+delegate.errorString())
 
45
        }
 
46
        if(timer.running)
 
47
            timer.restart()
 
48
    }
 
49
    
 
50
    property real endOfWindow: 1230
 
51
    ParallelAnimation {
 
52
        id: destroyAnimation
 
53
        NumberAnimation {
 
54
            id: fadeoutAnimation
 
55
            duration: 500
 
56
            to: viewItem.endOfWindow
 
57
            property: "anchors.leftMargin"
 
58
            easing.type: Easing.InQuad
 
59
        }
 
60
        NumberAnimation {
 
61
            duration: 500
 
62
            to: -viewItem.endOfWindow
 
63
            property: "anchors.rightMargin"
 
64
            target: fadeoutAnimation.target
 
65
            easing.type: fadeoutAnimation.easing.type
 
66
        }
 
67
        NumberAnimation {
 
68
            duration: 500
 
69
            from: 1
 
70
            to: 0
 
71
            property: "opacity"
 
72
            target: fadeoutAnimation.target
 
73
            easing.type: Easing.InQuad
 
74
        }
 
75
        NumberAnimation {
 
76
            id: fadeinAnimation
 
77
            duration: 500
 
78
            from: 0
 
79
            to: 1
 
80
            property: "opacity"
 
81
            target: viewItem.currentItem
 
82
            easing.type: Easing.InQuad
 
83
        }
 
84
        onCompleted: fadeoutAnimation.target.destroy()
 
85
    }
 
86
    
 
87
    function next() {
 
88
        viewItem.current = (viewItem.current+1)%dataModel.count
 
89
    }
 
90
    function previous() {
 
91
        var val = viewItem.current-1
 
92
        if(val<0)
 
93
            val = dataModel.count-1
 
94
        viewItem.current = val
 
95
    }
 
96
    
 
97
    MouseArea {
 
98
        anchors.fill: parent
 
99
        onClicked: info.next()
 
100
    }
 
101
    
 
102
    Timer {
 
103
        id: timer
 
104
        interval: 5000; running: viewItem.visible; repeat: true
 
105
        onTriggered: info.next()
 
106
    }
 
107
}
 
 
b'\\ No newline at end of file'