Introduced styles - first version of Widgets
[opentodolist:opentodolist.git] / OpenTodoList / qml / OpenTodoList / styles / neutral / views / TodoListContents.qml
1 /*
2  *  OpenTodoList - A todo and task manager
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 "../controls"
21
22 Item {
23     id: todoListContents
24
25     clip: true
26
27     property alias filterText: filterText.text
28
29     signal todoSelected(QtObject todo)
30
31     Column {
32         id: controlsColumns
33         spacing: 5
34         height: childrenRect.height
35
36         LinkLabel {
37             id: todoListName
38
39             label: todoListView.currentList ? todoListView.currentList.name : ""
40             width: parent.width
41             editable: true
42
43             onEditFinished: todoListView.currentList.name = todoListName.label
44
45             states: [
46                 State {
47                     name: "hidden"
48                     when: !todoListView.currentList
49                     PropertyChanges {
50                         target: todoListName
51                         height: 0
52                     }
53                 }
54             ]
55
56             transitions: [
57                 Transition {
58                     from: ""
59                     to: "hidden"
60                     reversible: true
61                     NumberAnimation {
62                         properties: "height"
63                         duration: 200
64                     }
65                 }
66             ]
67         }
68
69         Item {
70             height: todoListView.currentList ? Math.max( newTodoTitle.height, addNewTodoButton.height ) : 0
71             width: todoListContents.width
72             SimpleTextInput {
73                 id: newTodoTitle
74                 anchors { left: parent.left; right: parent.right; rightMargin: addNewTodoButton.width + 10 }
75                 text: ""
76                 placeholderText: "Add new todo"
77
78                 onApply: addNewTodoButton.createNewTodo()
79             }
80             Button {
81                 id: addNewTodoButton
82                 label: "\uf067"
83                 font.family: symbolFont.name
84
85                 anchors.right: parent.right
86
87                 onClicked: createNewTodo()
88
89                 function createNewTodo() {
90                     if ( newTodoTitle.text != "" ) {
91                         var todo = todoListView.currentList.addTodo();
92                         todo.title = newTodoTitle.text;
93                         newTodoTitle.text = "";
94                     }
95                 }
96             }
97             Behavior on height { SmoothedAnimation { velocity: 120 } }
98         }
99
100         Item {
101             id: filterItem
102             height: childrenRect.height
103             width: todoListContents.width
104             SimpleTextInput {
105                 id: filterText
106                 anchors { left: parent.left; right: parent.right }
107                 text: ""
108                 placeholderText: "Filter todos"
109
110                 onTextChanged: todoListView.filterText = text
111             }
112         }
113     }
114
115     TodoView {
116         width: todoListContents.width
117         anchors.top: controlsColumns.bottom
118         anchors.bottom: parent.bottom
119         model: todoListView.model
120
121         onTodoSelected: todoListContents.todoSelected(todo)
122     }
123 }