add some comments
[makneto-zunavac1.git] / src / ui-mobile / declarative / VideoWidget.qml
blobc9e94009f450c37a19a1e8d15886425d0b64589c
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  */
20 import QtQuick 1.0
21 import Qt 4.7
22 import Gst 1.0
24 Rectangle {
25     id: videoWidget
26     /*
27     width: 100
28     height: 62
29     */
30     color: "black"
33     function log(msg){
34         console.log("II [VideoWidget.qml]: "+msg);
35     }
36     function error(msg){
37         console.log("EE [VideoWidget.qml]: "+msg);
38     }
39     function warn(msg){
40         console.log("WW [VideoWidget.qml]: "+msg);
41     }
42     function setSessionsModel(model){
43         chatWidget.sendMessage.connect(model.sendTextMessage);
44     }
47     state: "normal"
48     states: [
49         State {
50             name: "normal"
51             PropertyChanges {
52                 target: stateIcon
53                 source: "img/fullscreen.png"
54             }
55             AnchorChanges {
56                 target: videoWidget;
57                 anchors.left: board.right;
58                 anchors.bottom: board.bottom
59             }
60         },
61         State {
62             name: "fullscreen"
63             PropertyChanges {
64                 target: stateIcon
65                 source: "img/minimize.png"
66             }
67             AnchorChanges {
68                 target: videoWidget;
69                 anchors.left: videoWidget.parent.left;
70                 anchors.bottom: videoWidget.parent.bottom
71             }
72         }
73     ]
75     property variant session;
76     property variant emptyVideoSurface: VideoSurface{}
77     property variant emptyPreviewSurface: VideoSurface{}
79     function videoSurfaceReady(type, sessionId, newSurface){
80         if (sessionId != session.sessionId)
81             return;
83         try{
84             log("video surface ready \""+type+"\" \""+sessionId+"\" "+newSurface+"");
85             //log(JSON.stringify());
87             if (type=="preview"){
88                 log("setting surface for previewVideoItem");
89                 previewVideoItem.surface = newSurface;
90             }else{
91                 log("setting surface for mainVideoItem");
92                 mainVideoItem.surface = newSurface;
93             }
94         }catch (e){
95             error(JSON.stringify(e));
96         }
97     }
98     function videoSurfaceRemoved(type, sessionId){
99         if (sessionId != session.sessionId)
100             return;
102         try{
103             log("video surface removed \""+type+"\" \""+sessionId+"\"");
104             //log(JSON.stringify(surface));
105             if (type=="preview"){
106                 previewVideoItem.surface = emptyPreviewSurface;
107             }else{
108                 mainVideoItem.surface = emptyVideoSurface;
109             }
110         }catch (e){
111             error(JSON.stringify(e));
112         }
114     }
116     Component.onCompleted:{
117         videoWidget.session = videoWidget.parent;
118         main.videoSurfaceReady.connect(videoSurfaceReady);
119         main.videoSurfaceRemoved.connect(videoSurfaceRemoved);
120     }
123     Behavior on width {
124         NumberAnimation{duration: 200}
125     }
126     Behavior on opacity {
127         NumberAnimation{duration: 200}
128     }
129     Behavior on height {
130         NumberAnimation{duration: 200}
131     }
133     transitions: Transition {
134            // smoothly reanchor myRect and move into new position
135            AnchorAnimation { duration: 200 }
136        }
139     Rectangle{
140         id: video
141         color: parent.color
142         BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
143         anchors{fill: parent; margins:4 }
145         Image{
146             source: "img/cam.svg"
147             anchors.centerIn: parent;
148             width: Math.min( parent.width / 3, parent.height / 3)
149             height: width
150         }
152         Rectangle{
153             id: videoWrapper
154             color: "transparent"
155             anchors.fill: parent
157             VideoItem {
158               id: mainVideoItem
159               surface: emptyVideoSurface
160               size: Qt.size(parent.width, parent.height)
161               //anchors.fill: parent
162             }
163         }
164         Rectangle{
165             anchors{left: parent.left; bottom: parent.bottom}
166             width: Math.max(80, Math.min(320, parent.width /3));
167             height: (width / 4) * 3
168             color: "#090909"
170             VideoItem {
171               id:previewVideoItem
172               surface: emptyPreviewSurface
173               size: Qt.size(parent.width, parent.height)
174             }
175         }
178         Image{
179             id: stateIcon
180             source: "img/fullscreen.png"
181             anchors{right: parent.right; bottom: parent.bottom}
182             width: 64
183             height: width
185             MouseArea{
186                 anchors.fill: parent
187                 onClicked: {
188                     //videoWidget.state = videoWidget.state == "normal"? "fullscreen": "normal"
189                     if (videoWidget.state == "normal")
190                         videoWidget.parent.fullScreenVideo();
191                     else
192                         videoWidget.parent.minimizeVideo();
193                 }
194             }
195         }
196     }