~saviq/unity/8.run-device-delete

« back to all changes in this revision

Viewing changes to Dash/DashVideos.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 "../Components"
 
20
import "../Components/ListItems" as ListItems
 
21
import "Video"
 
22
 
 
23
LensView {
 
24
    id: lensView
 
25
    property alias previewShown: previewLoader.onScreen
 
26
 
 
27
    onIsCurrentChanged: {
 
28
        pageHeader.resetSearch();
 
29
    }
 
30
 
 
31
    onMovementStarted: categoryView.showHeader()
 
32
 
 
33
    Binding {
 
34
        target: lensView.lens
 
35
        property: "searchQuery"
 
36
        value: pageHeader.searchQuery
 
37
    }
 
38
 
 
39
    Connections {
 
40
        target: panel
 
41
        onSearchClicked: if (isCurrent) {
 
42
            pageHeader.triggerSearch()
 
43
            categoryView.showHeader()
 
44
        }
 
45
    }
 
46
 
 
47
    /* Workaround for bug: https://bugreports.qt-project.org/browse/QTBUG-28403
 
48
       When using Loader to load external QML file in the list deelgate, the ListView has
 
49
       a bug where it can position the delegate content to overlap the section header
 
50
       of the ListView - a workaround is to use sourceComponent of Loader instead */
 
51
    Component { id: videosFilterGrid; VideosFilterGrid {} }
 
52
    Component { id: videosCarousel;   VideosCarousel {}   }
 
53
 
 
54
    function getRenderer(categoryId) {
 
55
        switch (categoryId) {
 
56
            case 0: return videosCarousel
 
57
            default: return videosFilterGrid
 
58
        }
 
59
    }
 
60
 
 
61
    OpenEffect {
 
62
        id: effect
 
63
        anchors {
 
64
            fill: parent
 
65
            bottomMargin: -bottomOverflow
 
66
        }
 
67
        sourceItem: categoryView
 
68
 
 
69
        enabled: gap > 0.0
 
70
 
 
71
        topGapPx: (1 - gap) * positionPx
 
72
        topOpacity: Math.max(0, (1 - gap * 1.2))
 
73
        bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
 
74
        bottomOverflow: units.gu(6)
 
75
        bottomOpacity: 1 - (gap * 0.8)
 
76
 
 
77
        property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
 
78
        property real gap: previewLoader.open ? 1.0 : 0.0
 
79
 
 
80
        Behavior on gap {
 
81
            NumberAnimation {
 
82
                duration: 200
 
83
                easing.type: Easing.InOutQuad
 
84
                onRunningChanged: {
 
85
                    if (!previewLoader.open && !running) {
 
86
                        previewLoader.onScreen = false;
 
87
                    }
 
88
                }
 
89
            }
 
90
        }
 
91
    }
 
92
 
 
93
    ListViewWithPageHeader {
 
94
        id: categoryView
 
95
        anchors.fill: parent
 
96
        model: lensView.categories
 
97
        clipListView: !previewLoader.onScreen
 
98
 
 
99
        onAtYEndChanged: if (atYEnd) endReached()
 
100
        onMovingChanged: if (moving && atYEnd) endReached()
 
101
 
 
102
        delegate: ListItems.Base {
 
103
            id: base
 
104
            highlightWhenPressed: false
 
105
            property int categoryIndex: index
 
106
            property int categoryId: id
 
107
 
 
108
            Loader {
 
109
                id: loader
 
110
                anchors { top: parent.top; left: parent.left; right: parent.right }
 
111
                sourceComponent: lensView.getRenderer(base.categoryId)
 
112
                onLoaded: {
 
113
                    item.model = results
 
114
                }
 
115
                asynchronous: true
 
116
 
 
117
                Connections {
 
118
                    target: loader.item
 
119
                    onClicked: {
 
120
                        var dataItem;
 
121
                        // VideosCarousel and VideosFilterGrid have different
 
122
                        // clicked signals, accomodate for that
 
123
                        if (categoryId == 0) {
 
124
                            var fileUri = delegateItem.model.column_0.replace(/^[^:]+:/, "")
 
125
                            dataItem = {fileUri: fileUri, nfoUri: delegateItem.model.column_5}
 
126
                        } else {
 
127
                            dataItem = data;
 
128
                        }
 
129
                        if (dataItem.nfoUri != "") {
 
130
                            previewLoader.videoData = dataItem;
 
131
                            previewLoader.open = true;
 
132
                            effect.positionPx = mapToItem(categoryView, 0, itemY).y;
 
133
                        }
 
134
                    }
 
135
                }
 
136
            }
 
137
        }
 
138
 
 
139
        sectionProperty: "name"
 
140
        sectionDelegate: ListItems.Header {
 
141
            width: categoryView.width
 
142
            text: section
 
143
        }
 
144
 
 
145
        pageHeader: PageHeader {
 
146
            id: pageHeader
 
147
            width: categoryView.width
 
148
            text: i18n.tr("Videos")
 
149
            searchEntryEnabled: true
 
150
            searchHistory: lensView.searchHistory
 
151
        }
 
152
    }
 
153
 
 
154
    Loader {
 
155
        id: previewLoader
 
156
        height: effect.bottomGapPx - effect.topGapPx
 
157
        anchors {
 
158
            top: parent.top
 
159
            topMargin: effect.topGapPx
 
160
            left: parent.left
 
161
            right: parent.right
 
162
        }
 
163
        sourceComponent: onScreen ? previewComponent : undefined
 
164
 
 
165
        property bool open: false
 
166
        property bool onScreen: false
 
167
        property var videoData
 
168
 
 
169
 
 
170
        onOpenChanged: {
 
171
            if (open) {
 
172
                onScreen = true;
 
173
            }
 
174
        }
 
175
 
 
176
        onLoaded: {
 
177
            item.item = videoData;
 
178
        }
 
179
    }
 
180
 
 
181
    Component {
 
182
        id: previewComponent
 
183
 
 
184
        VideoPreview {
 
185
            id: preview
 
186
            anchors.fill: parent
 
187
            onClose: open = false;
 
188
        }
 
189
    }
 
190
 
 
191
    // TODO: Move as InverseMouseArea to DashPreview
 
192
    MouseArea {
 
193
        enabled: previewLoader.onScreen
 
194
        anchors {
 
195
            fill: parent
 
196
            topMargin: effect.bottomGapPx
 
197
        }
 
198
        onClicked: {
 
199
            previewLoader.open = false;
 
200
        }
 
201
    }
 
202
 
 
203
}