Licensing (suite)
[quicknewsreader] / qml / QuickNewsReader / content / view / SourceDelegate.qml
1 /***
2 ** Copyright (C) 2012 Christophe CHAPUIS <chris.chapuis _at_ gmail _dot_ com>
3 **
4 ** This package 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 2 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This package 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 package; if not, write to the Free Software
16 ** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17 **
18 ***/
19 import QtQuick 1.0
20
21 Item {
22     id: delegate
23     width: delegate.ListView.view.width; height: 60
24
25     Text {
26         text: listSourceModel[index].name
27         color: delegate.ListView.isCurrentItem ? "white" : "black"
28         font { family: "Helvetica"; pixelSize: 16; bold: true }
29         anchors {
30             left: parent.left; leftMargin: 15
31             verticalCenter: parent.verticalCenter
32         }
33     }
34
35     BusyIndicator {
36         scale: 0.6
37         on: delegate.ListView.isCurrentItem && window.loading
38         anchors { right: parent.right; rightMargin: 10; verticalCenter: parent.verticalCenter }
39     }
40
41     Rectangle {
42         width: delegate.width; height: 1; color: "#cccccc"
43         anchors.bottom: delegate.bottom
44         visible: delegate.ListView.isCurrentItem ? false : true
45     }
46     Rectangle {
47         width: delegate.width; height: 1; color: "white"
48         visible: delegate.ListView.isCurrentItem ? false : true
49     }
50
51     MouseArea {
52         anchors.fill: delegate
53
54         onPressAndHold: {
55             // show the configuration for this journal
56             if( listSourceModel[index].hasSettings )
57             {
58                 window.showConfigDialog(index)
59             }
60         }
61
62         onClicked: {
63             if( delegate.ListView.view.currentIndex !== index )
64             {
65                 // here we remove everything in viewsModel after index our depth
66                 while(window.windowViewsModel.count>1)
67                     window.windowViewsModel.remove(window.windowViewsModel.count-1)
68
69                 delegate.ListView.view.currentIndex = index
70
71                 listSourceModel[index].currentPath = [index]
72
73                 window.windowViewsModel.append({ component: listSourceModel[index].listViews[0].viewComponent,
74                                                  componentDepth: 1 })
75
76                 //window.currentSourceIndex = index // doesn't work well with Qt 4.7.3 on Maemo...
77                 window.currentContentX = 1*window.width
78             }
79         }
80     }
81 }