init develop
[vietkaralist] / qml / vietkaralist / SongListView.qml
1 /*
2 Copyright (C) 2011  by Cuong Le <metacuong@gmail.com>
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, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>
16 */
17
18 import QtQuick 1.1
19
20 Rectangle {
21
22     id:container
23     width:parent.width
24
25     property alias songlistView: songlistView
26
27     anchors.verticalCenter: parent.verticalCenter
28     anchors.horizontalCenter: parent.horizontalCenter
29     anchors.fill: parent;anchors.topMargin: 55;anchors.leftMargin: 0;anchors.rightMargin: 0;anchors.bottomMargin: 30
30
31     Component {
32                  id: songlistDelegate
33                  Item {
34
35                      width: container.width; height: 80
36
37                      Rectangle {
38                          width: container.width
39                          height:1
40                          border.color: "grey"
41                      }
42
43                      Row {
44                          anchors.verticalCenter: parent.verticalCenter
45                          x:6
46                          Column {
47                              width: 80
48                                 Text {
49                                     text:model.number
50                                     font.bold: true
51                                     font.pixelSize: 20
52                                     color:"blue"
53                                 }
54                              }
55                          Column {
56                              width: 350
57                                 Text {
58                                     text:model.title
59                                     font.bold: true
60                                     font.pixelSize: 18
61                                 }
62                                 Text {
63                                     text:model.lyric
64                                     font.pixelSize: 16
65                                     font.italic: true
66                                     wrapMode: Text.WordWrap
67                                     width: 300
68                                 }
69                              }
70
71                           Column {
72                               width:100
73                               visible: container.width > container.height ? true : false
74                               Text {
75                                   text:model.author
76                                   font.bold: true
77                                   font.pixelSize: 18
78                               }
79                           }
80                          }
81
82
83                      MouseArea {
84                          anchors.fill: parent;
85                          onClicked:{
86                              songlistView.currentIndex = index;
87                          }
88                     }
89                  }
90              }
91
92     ListModel {
93         id: songlistModel
94
95         Component.onCompleted: {
96
97         }
98
99     }
100
101     Connections {
102         target:DBMan
103         onDbChanged:{
104         }
105         onAddSong:{
106             songlistModel.append({"number":m_number, "title":m_title, "lyric":m_lyric, "author":m_author})
107         }
108         onRemoveOldSongs:{
109             console.log("Remove old songs")
110             songlistModel.clear();
111         }
112     }
113
114     Component {
115         id: highlightsongDelegate
116         Rectangle {
117             width: container.width; height: songlistView.currentItem.height-6
118             color: "lightsteelblue"; radius: 5
119             y: songlistView.currentItem.y+4
120             border.color: "grey"
121             /*Behavior on y {
122                 SpringAnimation {
123                     spring: 4
124                     damping: 0.1
125                 }
126             }*/
127         }
128     }
129
130     Component {
131         id: sectionHeading
132         Rectangle {
133             width: container.width
134             height: childrenRect.height
135             color: "lightsteelblue"
136
137             Text {
138                 text: section
139                 font.bold: true
140             }
141         }
142     }
143
144
145     ListView {
146         id : songlistView
147         anchors.fill: parent
148         model: songlistModel
149         delegate: songlistDelegate
150         highlight: highlightsongDelegate
151         focus: true
152         highlightFollowsCurrentItem: false
153
154
155         section.property: "the_loai"
156         section.criteria: ViewSection.FullString
157         section.delegate: sectionHeading
158
159         ScrollBar{
160
161         }
162
163     }
164
165
166 }