rearch
[tlb/tlb-podcasts.git] / tlb / ui / qml / views / Summary.qml
1 import QtQuick 2.0
2 import QtQml.XmlListModel
3
4 import tlb.core 1.0
5 import "qrc:/tlb/ui/qml/templates"
6 /* import tlb.ui 1.0 */
7
8 /* This view provides a summary of all podcasts. */
9
10 /* Sorting modes:
11 * - marked favorite
12 * - alphabetical
13 * - most recent updated
14 * - most unlistened
15 * - most recently listened
16 * - most episodes listened
17 * - least episodes listened
18 * - recently added
19 * - added longest ago
20 * - most hours available
21 * - shortest average episode
22 * - longest average episode
23 */
24
25 /* with this fake data, provide a condensed list */
26 Page {
27 pageTitle: "Summary"
28
29 content: Item {
30 id: root
31
32 /* TODO: property holds fake data in it. */
33 /* readonly property var podcastNames: [ */
34 /* "pete q", */
35 /* "tom woods", */
36 /* "liberty report", */
37 /* "bob murphy", */
38 /* "buck johnson", */
39 /* "ancient faith" */
40 /* ] */
41
42 /* Load the real data from xml */
43 XmlListModel {
44 id: epModel
45 source: "file:///home/tlb/dev/git/android-qt-sandbox/example-data/collection_opml.xml"
46 query: "/opml/body/outline/outline"
47 XmlListModelRole { name: "title"
48 attributeName: "text" }
49 XmlListModelRole { name: "url"
50 attributeName: "xmlUrl" }
51 }
52
53 property bool pressDown: false
54 property real curMouseX: 0.0
55 property real curMouseY: 0.0
56 property real jumpPos: 0.0
57 /* property alias showBox: selector.visible */
58 property string selectedTitle: ""
59 property string selectedUrl: ""
60
61 function _common_released()
62 {
63 if(selectedTitle !== ""){
64 AppManager.shows.selectedName = selectedTitle
65 AppManager.shows.selected = selectedUrl;
66 AppManager.requestNewSource("qrc:/tlb/ui/qml/views/Show.qml")
67 }
68 }
69
70 Column {
71 id: col
72
73 anchors{
74 top: parent.top
75 left: parent.left
76 right: parent.right
77 margins: 20
78 }
79 spacing: 3
80 Repeater {
81 model: epModel
82 Rectangle {
83 id: rec
84
85 implicitHeight: t.height
86 width: col.width
87
88 property bool isHovered: {
89 if(root.pressDown){
90 var pnt = root.mapToItem(rec, root.curMouseX, root.curMouseY)
91
92 if(rec.contains(pnt)){
93 return true
94 }
95 }
96 return false
97 }
98
99 onIsHoveredChanged:{
100 if(isHovered){
101 var myMiddle = rec.height / 2
102 var newPoint = mapToItem(col, 0, myMiddle)
103 jumpPos = newPoint.y
104 /* showBox = true */
105 selectedTitle = title
106 selectedUrl = url
107 }else if(selectedTitle === title){
108 console.error(title + " no longer hovered")
109 /* showBox = false */
110 selectedTitle = ""
111 selectedUrl = ""
112 }
113 }
114
115 border {
116 color: isHovered ? "red" : "black"
117 width: 1
118 }
119
120 Text {
121 id: t
122 anchors {
123 left: parent.left
124 leftMargin: 5
125 verticalCenter: parent.verticalCenter
126 }
127 text: title
128 }
129 }
130 }
131 }
132
133 Rectangle {
134 id: selector
135 anchors {
136 right: col.right
137 }
138
139 /* init - can't be assed but this is magic */
140 y: jumpPos - 16
141 visible: false
142
143 color: "purple"
144 width: 70
145 height: 70
146 border {
147 width: 1
148 color: "yellow"
149 }
150 }
151
152 MouseArea {
153 anchors.fill: parent
154 onPositionChanged: (mouse)=> {
155 root.curMouseX = mouse.x
156 root.curMouseY = mouse.y
157 }
158 onPressed: (mouse)=> {
159 root.pressDown = true
160 root.curMouseX = mouse.x
161 root.curMouseY = mouse.y
162 }
163 onReleased: (mouse)=> {
164 console.error("main release event")
165
166 /* at this moment, check who is in control */
167 _common_released()
168
169 root.pressDown = false
170 root.curMouseX = mouse.x
171 root.curMouseY = mouse.y
172 }
173 }
174 }
175 }