14ec523d49ed7ed24c63af216ce8e866eced42bf
[quicknewsreader] / main.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 import "content/view"
21 import "content/modelimpl"
22 import "content/modelitf"
23
24 Rectangle {
25     id: window
26     //anchors.fill: parent // use this little trick to always adapt itself to the screen
27     width: 800; height: 480
28
29     property int currentSourceIndex: 0
30
31     property list<SourceModel> listSourceModel: [
32         LeMondeSourceModel{},
33         GoogleReaderSourceModel{},
34         FavoriteFeedsSourceModel{},
35         YahooSourceModel{}
36     ]
37
38     property variant currentSource: listSourceModel[currentSourceIndex]
39     property bool loading: currentSource.loading
40     property alias windowViewsModel: viewsModel
41     property alias windowViewsList: viewsList
42     property alias currentContentX: viewsList.contentX
43
44     ListModel {
45         id: viewsModel
46
47         ListElement { component: "content/view/Sources.qml"; componentDepth: 0 }
48     }
49
50
51     ListView {
52         id: viewsList
53
54         anchors.fill: window
55         orientation: ListView.Horizontal
56         snapMode: ListView.SnapOneItem
57         flickDeceleration: 500
58         cacheBuffer: 1600 // so that the next delegate gets actually loaded...
59         preferredHighlightBegin: window.x
60         preferredHighlightEnd: window.width
61         highlightRangeMode: ListView.StrictlyEnforceRange
62         boundsBehavior: Flickable.StopAtBounds
63
64         Behavior on contentX {
65             NumberAnimation { duration: 500; easing.type: Easing.InOutCubic }
66         }
67
68         model: viewsModel
69         delegate: Loader {
70             id: modelLoader
71             source: component
72
73             ListView.onAdd: {
74                 viewsList.contentX = componentDepth*window.width
75                 //viewsList.currentIndex = componentDepth  // doesn't work well with Qt 4.7.3 on Maemo...
76             }
77         }
78     }
79
80     function showConfigDialog(index) {
81         configDialog.configModel = listSourceModel[index]
82         configDialog.state = "showSourceConfig"
83     }
84
85     SourceConfigDialog {
86         id:configDialog
87     }
88
89 /*
90 */
91
92     Component {
93         id: quitButtonDelegate
94         Item {
95             width: parent.width; height: 60
96             Text {
97                 text: "Quit"
98                 font { family: "Helvetica"; pixelSize: 16; bold: true }
99                 anchors {
100                     left: parent.left; leftMargin: 15
101                     verticalCenter: parent.verticalCenter
102                 }
103             }
104             MouseArea {
105                 anchors.fill: parent
106                 onClicked: Qt.quit()
107             }
108         }
109     }
110 }