some UI changes for usability
[makneto-zunavac1.git] / src / ui-mobile / declarative / AbstractPopup.qml
bloba201bbb5c6989afbddf44570b725848413d8a2b3
1 /*
2  *   Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
3  *
4  *   This program 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 program 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 program; if not, write to the
16  *   Free Software Foundation, Inc.,
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  */
19 import QtQuick 1.0
21 Rectangle {
22     id: popup
23     anchors{fill:parent}
25     property variant wrapper: _wrapper
26     property int animationInLength: 500
27     property int animationOutLength: 500
28     property int popupFromX: parent.width
29     property int popupFromY: 0
30     property int finalWidth: parent.width * 0.8
31     property int finalHeight: parent.height * 0.8
32     property int minCorner: main.toolbarHeight
33     //property int minCorner: 50
34     property int finalX: (popupFromX - finalWidth) < minCorner ? minCorner: popupFromX - finalWidth
35     property int finalY: (popupFromY + finalHeight) > parent.height - minCorner ? parent.height - finalHeight - minCorner: popupFromY
36     property bool destroyOnHide: true
38     function log(msg){
39         console.log("II [AbstractPopup.qml]: "+msg);
40     }
41     function error(msg){
42         console.log("EE [AbstractPopup.qml]: "+msg);
43     }
44     function warn(msg){
45         console.log("WW [AbstractPopup.qml]: "+msg);
46     }
48     function hidePopup(){
49         popup.state = "hide";
50         if (destroyOnHide)
51             destroyTimer.start();
52     }
54     Timer {
55         id: destroyTimer
56         interval: animationOutLength; running: false; repeat: false
57         onTriggered: {
58             //log("destroy");
59             popup.destroy();
60         }
61     }
63     color: "transparent"
64     state: "hide"
66     states: [
67         State {
68             name: "hide"
69             PropertyChanges { target: background; opacity: 0 }
70             PropertyChanges { target: backgroundMouseArea; enabled: false}
71             PropertyChanges { target: wrapper; width: 0; height: 0; x: popupFromX; y: popupFromY; opacity: 0}
72         },
73         State {
74             name: "visible"
75             PropertyChanges { target: background; opacity: .5 }
76             PropertyChanges { target: backgroundMouseArea; enabled: true}
77             PropertyChanges { target: wrapper; width: finalWidth; height: finalHeight; x: finalX; y: finalY; opacity: 1}
78         }
79     ]
80     transitions: [
81         Transition {
82             from: "hide"; to: "visible"
83             NumberAnimation { properties: "width,height"; easing.type: Easing.InOutQuad; duration: animationInLength }
84             NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad; duration: animationInLength }
85             NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; duration: animationInLength }
86         },
87         Transition {
88             from: "visible"; to: "hide"
89             NumberAnimation { properties: "width,height"; easing.type: Easing.InOutQuad; duration: animationOutLength }
90             NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad; duration: animationOutLength }
91             NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; duration: animationOutLength }
92         }
93     ]
95     SystemPalette { id: syspal }
97     Rectangle{
98         id: background
99         color: "black"
100         anchors{fill:parent}
102         MouseArea{
103             id: backgroundMouseArea
104             anchors{fill:parent}
105             onClicked: {
106                 hidePopup();
107             }
108         }
109     }
110     Rectangle{
111         id: _wrapper
112         color: "transparent"
113         MouseArea{
114             id: wrapperMouseArea
115             anchors{fill:parent}
116         }
117     }
118     Rectangle{
119         height : main.toolbarHeight
120         width: height
121         radius : width / 2
122         z: 10
123         border.color: main.useSyspal? syspal.light :"white"
124         border.width: 1
125         color: main.useSyspal? syspal.mid :"#323235"
126         anchors.horizontalCenter: _wrapper.right
127         anchors.verticalCenter: _wrapper.top
128         opacity: _wrapper.opacity
130         /*
131         x: _wrapper.x + _wrapper.width - (width /2)
132         y: _wrapper.y - (height /2)
133         */
135         Image {
136             id: crossIcon
137             source: "img/cross.png"
138             //anchors.fill: parent
139             anchors.horizontalCenter: parent.horizontalCenter
140             anchors.verticalCenter: parent.verticalCenter
141             width: parent.width * .6
142             height: width
143         }
144         MouseArea{
145             anchors.fill: parent
146             onClicked: {
147                 hidePopup();
148             }
149         }
150     }