Storing window size and geometry
[opentodolist:opentodolist.git] / OpenTodoList / qml / OpenTodoList / controls / PriorityIndicator.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 "../js/Utils.js" as Utils
21
22 Item {
23     id: indicator
24
25     property int priority: 0
26     property int sizeOnFocus: layout.minimumButtonHeight * 4
27
28     signal selectedPriority(int priority)
29
30     Keys.onEscapePressed: focus = false
31
32     width: text.width + text.height
33     height: width
34
35     Item {
36         id: helper
37         readonly property color noColor: "#00000000"
38         property color hoveredColor: noColor
39         function noColorSelected() { return hoveredColor === noColor; }
40         Behavior on hoveredColor { ColorAnimation { duration: 50 } }
41     }
42
43     Image {
44         property color color: Utils.PriorityColors[priority]
45
46         anchors {
47             fill: parent
48         }
49         sourceSize.width: indicator.sizeOnFocus
50         sourceSize.height: indicator.sizeOnFocus
51         source: "image://primitives/pie/percentage=100,fill=" + color
52     }
53
54     MouseArea {
55         id: indicatorMouseArea
56         anchors.fill: parent
57         hoverEnabled: true
58         onClicked: indicator.focus = !indicator.focus
59     }
60
61     Text {
62         id: text
63         opacity: 1.0 - inner.opacity
64         anchors.centerIn: parent
65         text: indicator.priority >= 0 ? "Priority " + indicator.priority : "No Priority"
66         font.pointSize: fonts.p
67         color: colors.fontColorFor( Utils.PriorityColors[indicator.priority] )
68     }
69
70     Item {
71         id: inner
72
73         opacity: 0
74         anchors {
75             fill: parent
76             margins: 5
77         }
78
79         Repeater {
80             model: 12
81             Item {
82                 opacity: inner.opacity
83                 visible: opacity !== 0
84                 width: indicator.width / 6
85                 height: indicator.height * 9 / 10
86                 rotation: index * 360 / 12
87                 anchors.horizontalCenter: parent.horizontalCenter
88                 Image {
89                     width: parent.width
90                     height: parent.width
91                     sourceSize.width: layout.minimumButtonHeight
92                     sourceSize.height: layout.minimumButtonHeight
93                     source: "image://primitives/pie/percentage=100,fill=" +
94                             text.color
95                 }
96                 Image {
97                     width: parent.width - 4
98                     height: parent.width -4
99                     x: 2
100                     y: 2
101                     sourceSize.width: layout.minimumButtonHeight
102                     sourceSize.height: layout.minimumButtonHeight
103                     source: "image://primitives/pie/percentage=100,fill=" +
104                             Utils.PriorityColors[index-1]
105                 }
106                 MouseArea {
107                     width: parent.width
108                     height: parent.width
109                     hoverEnabled: true
110                     onClicked: {
111                         indicator.selectedPriority( index - 1 )
112                         indicator.focus = false;
113                     }
114                     onContainsMouseChanged: helper.hoveredColor =
115                                             containsMouse ?
116                                                 Utils.PriorityColors[index-1] :
117                                                 helper.noColor
118                 }
119             }
120         }
121     }
122
123     states: [
124         State {
125             name: "focused"
126             when: indicator.focus
127             PropertyChanges {
128                 target: indicator
129                 width: indicator.sizeOnFocus
130             }
131             PropertyChanges {
132                 target: inner
133                 opacity: 1.0
134             }
135         }
136     ]
137
138
139     transitions: [
140         Transition {
141             from: ""
142             to: "focused"
143             reversible: true
144             SequentialAnimation {
145                 NumberAnimation {
146                     target: indicator
147                     property: "width"
148                     duration: 200
149                 }
150                 NumberAnimation {
151                     target: inner
152                     property: "opacity"
153                     duration: 200
154                 }
155             }
156         }
157     ]
158 }