~juliank/software-center/debian

« back to all changes in this revision

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

  • Committer: Julian Andres Klode
  • Date: 2011-11-20 13:34:41 UTC
  • mfrom: (429.62.1824 software-center)
  • Revision ID: jak@debian.org-20111120133441-npw6j3nmd8v75yav
Merge from 2.0.7 up to 5.1.2 pre-release

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
FocusScope {
 
23
    id: frameSwitch
 
24
 
 
25
    property int duration: 200
 
26
    property alias currentIndex: frames.currentIndex
 
27
    property alias count: frames.count
 
28
 
 
29
    clip: true
 
30
 
 
31
    ListModel {
 
32
        id: frames
 
33
        property int currentIndex: -1
 
34
    }
 
35
 
 
36
    onWidthChanged: {
 
37
        for (var i = 0; i < frames.count; i++) {
 
38
            frames.get(i).frame.width = frameSwitch.width
 
39
        }
 
40
        if (frames.count > 0) {
 
41
            frames.get(0).frame.x = -frameSwitch.width * frames.currentIndex
 
42
        }
 
43
    }
 
44
 
 
45
    function pushFrame(frame) {
 
46
        frame.duration = frameSwitch.duration
 
47
        frames.append({ frame: frame })
 
48
        frame.parent = frameSwitch
 
49
        frame.width = frame.parent.width
 
50
        frame.anchors.top = frame.parent.top
 
51
        frame.anchors.bottom = frame.parent.bottom
 
52
        if (frames.count == 1) {
 
53
            frame.x = 0
 
54
            frame.focus = true
 
55
            frames.currentIndex = 0
 
56
        } else {
 
57
            frame.anchors.left = frames.get(frames.count - 2).frame.right
 
58
        }
 
59
    }
 
60
 
 
61
    function currentFrame() {
 
62
        if (frames.count > 0) {
 
63
            return frames.get(frames.currentIndex).frame
 
64
        } else {
 
65
            return null
 
66
        }
 
67
    }
 
68
 
 
69
    function changeIndex(newIndex) {
 
70
        if (frames.count <= 1) return
 
71
        if (frames.currentIndex == newIndex) return
 
72
        if (newIndex < 0 || newIndex >= frames.count) return
 
73
        frameConnection.target = frames.get(0).frame
 
74
        frames.get(0).frame.x = -frameSwitch.width * newIndex
 
75
        frames.currentIndex = newIndex
 
76
    }
 
77
 
 
78
    function goToFrame(frame) {
 
79
        for (var i = 0; i < frames.count; i++) {
 
80
            if (frames.get(i).frame == frame) {
 
81
                changeIndex(i)
 
82
                break
 
83
            }
 
84
        }
 
85
    }
 
86
 
 
87
    Connections {
 
88
        id: frameConnection
 
89
        target: null
 
90
        onRunningChanged: {
 
91
            if (!frameConnection.target.running) {
 
92
                frameConnection.target = null
 
93
                currentFrame().shown()
 
94
                currentFrame().focus = true
 
95
            }
 
96
        }
 
97
    }
 
98
}
 
99