Some changes for better touch support and scripts
[opentodolist:opentodolist.git] / OpenTodoList / qml / OpenTodoList / TodoListView.qml
1 /*
2  *  OpenTodoListDesktopQml - Desktop QML frontend for OpenTodoList
3  *  Copyright (C) 2013  Martin Höher <martin@rpdev.net>
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 import QtQuick 2.0
20 import net.rpdev.OpenTodoList 1.0
21 import "Utils.js" as Utils
22
23 View {
24     id: todoListView
25
26     property QtObject currentList : null
27
28     property string filterText
29
30     property TodoSortFilterModel allTopLevelTodos : TodoSortFilterModel {
31         sourceModel: library.todos
32         filterMode: TodoSortFilterModel.TodoListEntries | TodoSortFilterModel.HideDeleted
33     }
34
35     property TodoSortFilterModel dueTodayModel : TodoSortFilterModel {
36         sourceModel: library.todos
37         maxDueDate: new Date()
38     }
39
40     property TodoSortFilterModel dueThisWeekModel : TodoSortFilterModel {
41         sourceModel: library.todos
42         maxDueDate: Utils.getLastDateOfWeek()
43     }
44
45     property TodoSortFilterModel model : TodoSortFilterModel {
46         sourceModel: layout.useCompactLayout ? null : allTopLevelTodos
47         searchString: filterText
48         sortMode: TodoSortFilterModel.PrioritySort
49     }
50
51     signal resetFilter()
52
53     onCurrentListChanged: {
54         filterText = "";
55         resetFilter();
56     }
57
58     onModelChanged: {
59         filterText = "";
60         resetFilter();
61     }
62
63     signal todoSelected(QtObject todo)
64     signal showTrashForList( QtObject list )
65     signal showSearch()
66     signal todoListClicked(QtObject list)
67
68     onResetFilter: filterText = ""
69
70     toolButtons: [
71         ToolButton {
72             label: "New List"
73
74             onClicked: newTodoListView.hidden = false
75         },
76         ToolButton {
77             label: "\uf002"
78             font.family: symbolFont.name
79
80             onClicked: todoListView.showSearch()
81         },
82         ToolButton {
83             label: "\uf014"
84             font.family: symbolFont.name
85             enabled: todoListView.currentList !== null
86
87             onClicked: if ( todoListView.currentList ) {
88                            todoListView.showTrashForList( todoListView.currentList );
89                        }
90         },
91         ToolButton {
92             font.family: symbolFont.name
93             label: "\uf011"
94
95             onClicked: Qt.quit()
96         }
97
98     ]
99     
100     Rectangle {
101         id: sideBar
102
103         width: layout.useCompactLayout ? parent.width : 300
104         height: todoListView.clientHeight
105         color: colors.primary
106         
107         Behavior on width { SmoothedAnimation { velocity: 1200 } }
108
109         Image {
110             id: linkToWebPage
111             source: "rpdevlogo_webheader.png"
112             anchors.bottom: parent.bottom
113             anchors.bottomMargin: 10
114             anchors.horizontalCenter: parent.horizontalCenter
115         }
116
117         MouseArea {
118             anchors.fill: linkToWebPage
119             onClicked: Qt.openUrlExternally( "http://www.rpdev.net/home/project/opentodolist" )
120             cursorShape: Qt.PointingHandCursor
121         }
122         
123         Flickable {
124             width: parent.width
125             anchors.top: parent.top
126             anchors.bottom: linkToWebPage.top
127             contentWidth: width
128             contentHeight: todoListColumn.height
129             clip: true
130
131             Column {
132                 id: todoListColumn
133                 width: parent.width
134
135                 Button {
136                     id: showAllTodosButton
137                     label: "All Todos"
138                     down: todoListView.model.sourceModel === todoListView.allTopLevelTodos
139                     width: parent.width
140
141                     onClicked: {
142                         todoListView.currentList = null;
143                         todoListView.model.sourceModel = todoListView.allTopLevelTodos
144                         todoListView.todoListClicked( null )
145                     }
146                 }
147
148                 Button {
149                     id: showTodosDueToday
150                     label: "Due Today"
151                     down: todoListView.model.sourceModel === todoListView.dueTodayModel
152                     width: parent.width
153
154                     onClicked: {
155                         todoListView.currentList = null;
156                         todoListView.model.sourceModel = todoListView.dueTodayModel
157                         todoListView.todoListClicked( null )
158                     }
159                 }
160
161                 Button {
162                     id: showTodosDueThisWeek
163                     label: "Due This Week"
164                     down: todoListView.model.sourceModel === todoListView.dueThisWeekModel
165                     width: parent.width
166
167                     onClicked: {
168                         todoListView.currentList = null;
169                         todoListView.model.sourceModel = todoListView.dueThisWeekModel
170                         todoListView.todoListClicked( null )
171                     }
172                 }
173
174                 Repeater {
175                     model: library.todoLists
176                     delegate: Button {
177                         width: parent.width
178                         label: object.name
179                         down: todoListView.currentList == object
180
181                         onClicked: {
182                             todoListView.currentList = object
183                             todoListView.model.sourceModel = object.entries
184                             todoListView.todoListClicked( object )
185                         }
186                     }
187                 }
188             }
189         }
190     }
191     
192     TodoListContents {
193         anchors.left: sideBar.right
194         anchors.leftMargin: 10
195         anchors.right: parent.right
196         height: parent.height
197
198         onTodoSelected: todoListView.todoSelected( todo )
199     }
200
201     Item {
202         Timer {
203             interval: 60000
204             onTriggered: {
205                 dueTodayModel.maxDueDate = new Date()
206                 dueThisWeekModel.maxDueDate = Utils.getLastDateOfWeek()
207             }
208         }
209     }
210
211 }