Correct bug on websocket
[cicn.git] / qml / Viper / ControlPanel.qml
1 /******************************************************************************
2     QtAV:  Multimedia framework based on Qt and FFmpeg
3     Copyright (C) 2012-2016 Wang Bin <[email protected]>
4 *   This file is part of QtAV (from 2013)
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9     This library 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 GNU
12     Lesser General Public License for more details.
13     You should have received a copy of the GNU Lesser General Public
14     License along with this library; if not, write to the Free Software
15     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16 ******************************************************************************/
17
18 import QtQuick 2.0
19 import "utils.js" as Utils
20 import QtQuick.Window 2.1
21 import QtAV 1.4
22
23 Rectangle {
24     id: root
25     function scaled(x) {
26         console.log("Screen " + screenPixelDensity + "; r: " + Screen.pixelDensity/Screen.logicalPixelDensity + "; size: " + Screen.width + "x" + Screen.height);
27         console.log("screen density logical: " + Screen.logicalPixelDensity + " pixel: " + Screen.pixelDensity + "; " + x + ">>>" +x*Screen.pixelDensity/Screen.logicalPixelDensity);
28         return x*Screen.pixelDensity/Screen.logicalPixelDensity;
29     }
30
31     color: "black"
32     opacity: 0.9
33     radius: Utils.scaled(10)
34     height: Utils.scaled(80)
35     width: itemWidth-25*pixDens
36
37     property string playState: "stop"
38     property int duration: 0
39     property real volume: 1
40     property bool mute: false
41     property bool hiding: false
42     signal startGraph
43     signal pauseGraph
44     signal stopGraph
45     signal resizeWindowFullScreen
46     signal resizeWindow
47     signal openMpd
48     signal openOptions
49     signal openOptionConnections
50     signal openGraph
51     signal hideGraph
52     signal repeatVideo
53     signal donotRepeatVideo
54     signal saveFullScreen
55     signal saveExitFullScreen
56     signal togglePause
57     signal showInfo
58     signal showHelp
59     signal openFile
60     signal openUrl
61     signal downloadMPD
62
63     function setPlayingProgress(value)
64     {
65         playState = "play"
66     }
67
68     function setStopState()
69     {
70         isPlaying = "stop"
71         playBtn.checked = false
72
73     }
74
75     function setPlayingState() {
76         playBtn.checked = true
77         playState = "play"
78
79     }
80
81     function setPauseState() {
82         playBtn.checked = false
83         playState = "pause"
84     }
85
86     function toggleFullScreen() {
87         fullScreenBtn.checked = !fullScreenBtn.checked
88     }
89
90     gradient: Gradient {
91         GradientStop { position: 0.0; color: "#88445566" }
92         GradientStop { position: 0.618; color: "#cc1a2b3a" }
93         GradientStop { position: 1.0; color: "#ee000000" }
94     }
95
96     MouseArea {
97         anchors.fill: parent
98         hoverEnabled: true
99         onHoveredChanged: {
100             if (containsMouse) {
101                 if (timer.running) //timer may ran a few seconds(<3) ago
102                     timer.stop();
103                 root.aniShow()
104             } else {
105
106             }
107         }
108
109         onPressed: {
110             if (timer.running) //timer may ran a few seconds(<3) ago
111                 timer.stop();
112             root.aniShow()
113         }
114     }
115
116     ProgressBar {
117         id: progress
118         objectName: "progress"
119
120         anchors {
121             top: parent.top
122             topMargin: Utils.scaled(8)
123             left: parent.left
124             leftMargin: Utils.scaled(20)
125             right: parent.right
126             rightMargin: Utils.scaled(20)
127         }
128         height: Utils.scaled(8)
129         onValueChangedByUi: {
130             dashPlayer.seekVideo(value);
131         }
132
133         onEnter: {
134             if (playState == "stop")
135                 return
136         }
137
138         onLeave: {
139             if (playState == "stop")
140                 return
141         }
142         onHoverAt: {
143             if (playState == "stop")
144                 return;
145         }
146     }
147
148     Item {
149         layer.enabled: true
150         anchors {
151             top: progress.bottom
152             bottom: parent.bottom
153             left: parent.left
154             right: parent.right
155             margins: Utils.scaled(8)
156         }
157
158         Text {
159             id: now
160             objectName: "now"
161             text: "00:00:00"//Utils.msec2string(progress.value*duration)
162             anchors {
163                 top: parent.top
164                 topMargin: Utils.scaled(2)
165                 left: parent.left
166             }
167             color: "white"
168             font {
169                 pixelSize: Utils.scaled(12) //or point size?
170             }
171         }
172         Text {
173             id: life
174             objectName: "life"
175             text: "00:00:00"//Utils.msec2string(duration)
176             anchors {
177                 top: parent.top
178                 topMargin: Utils.scaled(2)
179                 right: parent.right
180             }
181             color: "white"
182             font {
183                 pixelSize: Utils.scaled(12)
184             }
185         }
186         Button {
187             id: playBtn
188             enabled: true
189             objectName: "playBtn"
190             anchors.centerIn: parent
191             checkable: true
192             bgColor: "transparent"
193             bgColorSelected: "transparent"
194             width: Utils.scaled(50)
195             height: Utils.scaled(50)
196             icon: "qrc:///qml/images/play.svg"
197             iconChecked: "qrc:///qml/images/pause.svg"
198
199             onClicked: {
200                 if (checked === true) {
201                     console.log(adaptationLogic)
202                     dashPlayer.downloadMPD(adaptationLogic, icn)
203                 } else {
204                     dashPlayer.pause();
205                 }
206             }
207         }
208
209         Button {
210             id: stopBtn
211             enabled: true
212             anchors.verticalCenter: playBtn.verticalCenter
213             anchors.right: playBtn.left
214             bgColor: "transparent"
215             bgColorSelected: "transparent"
216             width: Utils.scaled(35)
217             height: Utils.scaled(35)
218             icon: "qrc:///qml/images/stop.svg"
219             onClicked: {
220                 playBtn.checked = false
221                 isPlaying = false
222                 canBuffer = false
223                 dashPlayer.onStopButtonPressed()
224             }
225         }
226
227         Button {
228             id: fullScreenBtn
229             anchors.left: parent.left
230             anchors.leftMargin: Utils.scaled(60)
231             anchors.verticalCenter: parent.verticalCenter
232             checkable: true
233             bgColor: "transparent"
234             bgColorSelected: "transparent"
235             width: Utils.scaled(30)
236             height: Utils.scaled(30)
237             icon: "qrc:///qml/images/fullscreen.png"
238             iconChecked: "qrc:///qml/images/fullscreen-selected.png"
239             visible: (Qt.platform.os != "android")
240             checked: enabledFullScreen
241             onCheckedChanged: {
242                 if (checked) {
243                     fullScreen()
244                     saveFullScreen()
245                 } else {
246                     exitFullScreen()
247                     saveExitFullScreen()
248                 }
249             }
250         }
251
252         Row {
253             anchors.right: parent.right
254             anchors.rightMargin: Utils.scaled(70)
255             anchors.verticalCenter: parent.verticalCenter
256             spacing: Utils.scaled(20)
257
258             Button {
259                 id: graphBtn
260                 bgColor: "transparent"
261                 bgColorSelected: "transparent"
262                 checkable: true
263                 width: Utils.scaled(30)
264                 height: Utils.scaled(30)
265                 icon: "qrc:///qml/images/graph.png"
266                 iconChecked: "qrc:///qml/images/graph-selected.png"
267                 visible: true
268                 checked: graph
269                 onCheckedChanged: {
270                     if ( !graphBtn.checked) {
271                         hideGraph()
272                     } else {
273                         openGraph()
274                     }
275                 }
276             }
277
278             Button {
279                 id: optionsBtn
280                 bgColor: "transparent"
281                 bgColorSelected: "transparent"
282                 checkable: true
283                 width: Utils.scaled(30)
284                 height: Utils.scaled(30)
285                 icon: "qrc:///qml/images/options.png"
286                 iconChecked: "qrc:///qml/images/options-selected.png"
287                 visible: true
288                 onCheckedChanged: {
289                     if (checked)
290                         openOptions()
291                 }
292             }
293
294             Button {
295                 id: optionConnectionsBtn
296                 bgColor: "transparent"
297                 bgColorSelected: "transparent"
298                 checkable: true
299                 width: Utils.scaled(30)
300                 height: Utils.scaled(30)
301                 icon: "qrc:///qml/images/option-connections.png"
302                 iconChecked: "qrc:///qml/images/option-connections-selected.png"
303                 visible: true
304                 onCheckedChanged: {
305
306                     if (checked)
307                         openOptionConnections()
308                 }
309             }
310
311    /*         Button {
312                 id: openBtn
313                 bgColor: "transparent"
314                 bgColorSelected: "transparent"
315                 checkable: true
316                 width: Utils.scaled(30)
317                 height: Utils.scaled(30)
318                 icon: "qrc:///qml/images/open.png"
319                 iconChecked: "qrc:///qml/images/open-selected.png"
320                 onCheckedChanged: {
321                     if(checked)
322                         openMpd()
323                 }
324             } */
325             Button {
326                 id: repeatBtn
327                 bgColor: "transparent"
328                 bgColorSelected: "transparent"
329                 checkable: true
330                 width: Utils.scaled(30)
331                 height: Utils.scaled(30)
332                 icon: "qrc:///qml/images/repeat.png"
333                 iconChecked: "qrc:///qml/images/repeat-selected.png"
334                 checked: repeat
335                 onCheckedChanged: {
336                     if ( !repeatBtn.checked) {
337                         donotRepeatVideo()
338                     } else {
339                         repeatVideo()
340                     }
341
342                 }
343
344             }
345         }
346     }
347
348     Timer {
349         id: timer
350         interval: 3000
351         onTriggered: {
352             root.aniHide()
353         }
354     }
355
356     function hideIfTimedout()
357     {
358         timer.start()
359     }
360
361     PropertyAnimation {
362         id: anim
363         target: root
364         properties: "opacity"
365         function reverse()
366         {
367             duration = 1500
368             to = 0
369             from = root.opacity
370         }
371
372         function reset()
373         {
374             duration = 200
375             from = root.opacity
376             to = 0.9
377         }
378     }
379
380     function aniShow()
381     {
382         hiding = false
383         anim.stop()
384         anim.reset()
385         anim.start()
386     }
387
388     function aniHide()
389     {
390         hiding = true
391         anim.stop()
392         anim.reverse()
393         anim.start()
394     }
395
396     function toggleVisible()
397     {
398         if (hiding)
399             aniShow()
400         else
401             aniHide()
402     }
403
404     function enable()
405     {
406         playBtn.enabled = true
407         stopBtn.enabled = true
408     }
409
410     function disable()
411     {
412         playBtn.enabled = false
413         stopBtn.enabled = false
414     }
415
416
417     function fullScreen()
418     {
419         requestFullScreen()
420         resizeWindowFullScreen()
421     }
422
423     function exitFullScreen()
424     {
425         requestNormalSize()
426         resizeWindow()
427     }
428
429     function checkRepeatButton()
430     {
431         repeatBtn.checked = !repeatBtn.checked;
432     }
433
434     function uncheckOpenBtn()
435     {
436         openBtn.checked = false;
437     }
438
439     function enableOpenBtn()
440     {
441         openBtn.enabled = true;
442     }
443
444     function uncheckOptionsBtn()
445     {
446
447         optionsBtn.checked = false;
448     }
449
450     function uncheckOptionConnectionsBtn()
451     {
452
453         optionConnectionsBtn.checked = false;
454     }
455
456     function enableOptionsBtn()
457     {
458         optionsBtn.enabled = true;
459     }
460 }