summaryrefslogtreecommitdiff
path: root/qt/main.qml
blob: d06b0d48f2977cde689485086612abc0339a7c8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/* GStreamer
 *
 * Copyright (C) 2015 Alexandre Moreno <alexmorenocano@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

import QtQuick 2.4
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.3
import QtQuick.Dialogs 1.2
import QtQuick.Window 2.1
import Player 1.0
import org.freedesktop.gstreamer.GLVideoItem 1.0

import "fontawesome.js" as FontAwesome

ApplicationWindow {
    id: window
    visible: true
    width: 640
    height: 480
    x: 30
    y: 30
    color: "black"
//    title : player.mediaInfo.title

    Player {
        id: player
        objectName: "player"
        volume: 0.5
        positionUpdateInterval: 100
        onStateChanged: {
            if (state === Player.STOPPED) {
                playbutton.state = "play"
            }
        }
        onResolutionChanged: {
            if (player.videoAvailable) {
                window.width = resolution.width
                window.height = resolution.height
            }
        }
    }

    GstGLVideoItem {
        id: video
        objectName: "videoItem"
        anchors.centerIn: parent
        width: parent.width
        height: parent.height
    }

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        onPositionChanged: {
            playbar.opacity = 1.0
            hidetimer.start()
        }
    }

    Timer {
        id: hidetimer
        interval: 5000
        onTriggered: {
            playbar.opacity = 0.0
            settings.visible = false
            stop()
        }
    }

    FileDialog {
        id: fileDialog
        //nameFilters: [TODO globs from mime types]
        onAccepted: player.source = fileUrl
    }

    Action {
        id: fileOpenAction
        text: "Open"
        onTriggered: fileDialog.open()
    }

    Item {
        anchors.fill: parent
        FontLoader {
            source: "fonts/fontawesome-webfont.ttf"
        }

        Rectangle {
            id : playbar
            color: Qt.rgba(1, 1, 1, 0.7)
            border.width: 1
            border.color: "white"
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 15
            anchors.horizontalCenter: parent.horizontalCenter
            width : grid.width + 20
            height: 40//childrenRect.height + 20
            radius: 5

            Rectangle {
                id: settings
                width: 150; height: settingsView.contentHeight
                color: Qt.rgba(1, 1, 1, 0.7)
                anchors.right: parent.right
                anchors.bottom: parent.top
                anchors.bottomMargin: 3
                border.width: 1
                border.color: "white"
                radius: 5
                visible: false

                ListModel {
                    id: settingsModel
                    ListElement {
                        name: "Video"
                    }
                    ListElement {
                        name: "Audio"
                    }
                    ListElement {
                        name: "Subtitle"
                    }
                }

                Component {
                    id: settingsDelegate
                    Item {
                        width: 150; height: 20
                        Text {
                            text: model.name
                            font.pointSize: 13
                            anchors.centerIn: parent
                        }

                        Text {
                            font.pointSize: 13
                            font.family: "FontAwesome"
                            text: FontAwesome.Icon.ChevronRight
                            anchors.right: parent.right
                            anchors.rightMargin: 10
                            anchors.verticalCenter: parent.verticalCenter
                        }

                        MouseArea {
                           anchors.fill: parent
                           onClicked: {
                               switch(name) {
                               case 'Video':
                                   videos.visible = true
                                   break
                               case 'Audio':
                                   audios.visible = true
                                   break
                               case 'Subtitle' :
                                   subtitles.visible = true
                                   break
                               }
                               settings.visible = false
                           }
                        }
                    }
                }

                ListView {
                    id: settingsView
                    anchors.fill: parent
                    model: settingsModel
                    delegate: settingsDelegate
                }
            }

            Rectangle {
                id: videos
                width: 150; height: videoView.contentHeight
                color: Qt.rgba(1, 1, 1, 0.7)
                anchors.right: parent.right
                anchors.bottom: parent.top
                anchors.bottomMargin: 3
                border.width: 1
                border.color: "white"
                radius: 5

                property bool selected: ListView.isCurrentItem
                visible: false

                Component {
                    id: videoDelegate
                    Item {
                        width: 150; height: 20
                        Text {
                            text: model.modelData.resolution.width + 'x' + model.modelData.resolution.height
                            font.pointSize: 13
                            anchors.centerIn: parent
                        }

                        MouseArea {
                           anchors.fill: parent
                           onClicked: {
                               parent.ListView.view.currentIndex = index
                               player.currentVideo = model.modelData
                           }
                       }
                    }
                }

                ListView {
                    id : videoView
                    anchors.fill: parent
                    model: player.mediaInfo.videoStreams
                    delegate: videoDelegate
                    highlight: Rectangle {
                        color: "white"
                        radius: 5
                        border.width: 1
                        border.color: "white"
                    }
                    focus: true
                    clip: true
                }
            }

            Rectangle {
                id: audios
                width: 150; height: audioView.contentHeight
                color: Qt.rgba(1, 1, 1, 0.7)
                anchors.right: parent.right
                anchors.bottom: parent.top
                anchors.bottomMargin: 3
                border.width: 1
                border.color: "white"
                radius: 5

                property bool selected: ListView.isCurrentItem
                visible: false

                Component {
                    id: audioDelegate
                    Item {
                        width: 150; height: 20
                        Text {
                            text: model.modelData.channels + 'channels'
                            font.pointSize: 13
                            anchors.centerIn: parent
                        }

                        MouseArea {
                           anchors.fill: parent
                           onClicked: {
                               parent.ListView.view.currentIndex = index
                               player.currentAudio = model.modelData
                           }
                       }
                    }
                }

                ListView {
                    id : audioView
                    anchors.fill: parent
                    model: player.mediaInfo.audioStreams
                    delegate: audioDelegate
                    highlight: Rectangle {
                        color: "white"
                        radius: 5
                        border.width: 1
                        border.color: "white"
                    }
                    focus: true
                    clip: true
                }
            }

            Rectangle {
                id: subtitles
                width: 150; height: subtitleView.contentHeight
                color: Qt.rgba(1, 1, 1, 0.7)
                anchors.right: parent.right
                anchors.bottom: parent.top
                anchors.bottomMargin: 3
                border.width: 1
                border.color: "white"
                radius: 5

                property bool selected: ListView.isCurrentItem
                visible: false

                Component {
                    id: subtitleDelegate
                    Item {
                        width: 150; height: 20
                        Text {
                            text: model.modelData.language
                            font.pointSize: 13
                            anchors.centerIn: parent
                        }

                        MouseArea {
                           anchors.fill: parent
                           onClicked: {
                               parent.ListView.view.currentIndex = index
                               player.currentSubtitle = model.modelData
                           }
                       }
                    }
                }

                ListView {
                    id : subtitleView
                    anchors.fill: parent
                    model: player.mediaInfo.subtitleStreams
                    delegate: subtitleDelegate
                    highlight: Rectangle {
                        color: "white"
                        radius: 5
                        border.width: 1
                        border.color: "white"
                    }
                    focus: true
                    clip: true
                }
            }

            Grid {
                id: grid
                anchors.horizontalCenter: parent.horizontalCenter
                spacing: 7
                rows: 1
                verticalItemAlignment: Qt.AlignVCenter

                Text {
                    id : openmedia
                    font.pointSize: 17
                    font.family: "FontAwesome"
                    text: FontAwesome.Icon.FolderOpen

                    MouseArea {
                       anchors.fill: parent
                       onPressed: fileDialog.open()
                    }
                }

                Item {
                    width: 17
                    height: 17

                    Text {
                        anchors.centerIn: parent
                        font.pointSize: 17
                        font.family: "FontAwesome"
                        text: FontAwesome.Icon.StepBackward
                    }
                }

                Item {
                    width: 25
                    height: 25

                    Text {
                        anchors.centerIn: parent
                        id : playbutton
                        font.family: "FontAwesome"
                        state: "play"

                        states: [
                            State {
                                name: "play"
                                PropertyChanges {
                                    target: playbutton
                                    text: FontAwesome.Icon.PlayCircle
                                    font.pointSize: 25
                                }
                            },
                            State {
                                name: "pause"
                                PropertyChanges {
                                    target: playbutton
                                    text: FontAwesome.Icon.Pause
                                    font.pointSize: 17
                                }
                            }
                        ]
                    }

                    MouseArea {
                       id: playArea
                       anchors.fill: parent
                       onPressed: {
                           if (player.state !== Player.PLAYING) {
                               player.play()
                               playbutton.state = "pause"
                           } else {
                               player.pause()
                               playbutton.state = "play"
                           }
                       }
                    }
                }

                Item {
                    width: 17
                    height: 17

                    Text {
                        anchors.centerIn: parent
                        font.pointSize: 17
                        font.family: "FontAwesome"
                        text: FontAwesome.Icon.StepForward
                    }
                }

                Item {
                    width: 40
                    height: 17
                    Text {
                        id: timelabel
                        anchors.centerIn: parent
                        font.pointSize: 13
                        color: "black"
                        text: {
                            var current = new Date(Math.floor(slider.value / 1e6));
                            current.getMinutes() + ":" + ('0'+current.getSeconds()).slice(-2)
                        }
                    }
                }

                Item {
                    width: 200
                    height: 38
                    Text {
                        anchors.centerIn: parent
                        width: parent.width
                        text: player.mediaInfo.title
                        font.pointSize: 15
                        elide: Text.ElideRight
                    }
                }

                Item {
                    width: 40
                    height: 17
                    Text {
                        id: durationlabel
                        anchors.centerIn: parent
                        font.pointSize: 13
                        color: "black"
                        text: {
                            var duration = new Date(Math.floor(player.duration / 1e6));
                            duration.getMinutes() + ":" + ('0'+duration.getSeconds()).slice(-2)
                        }
                    }
                }

                Text {
                    id: sub
                    font.pointSize: 17
                    font.family: "FontAwesome"
                    text: FontAwesome.Icon.ClosedCaptions
                    color: player.subtitleEnabled ? "red" : "black"

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            player.subtitleEnabled = !player.subtitleEnabled
                        }
                    }
                }

                Item {
                    width: 17
                    height: 17

                    Text {
                        id : volume
                        anchors.centerIn: parent
                        font.pointSize: 17
                        font.family: "FontAwesome"
                        text: {
                            if (volumeslider.value > volumeslider.maximumValue / 2) {
                                FontAwesome.Icon.VolumeUp
                            } else if (volumeslider.value === 0) {
                                FontAwesome.Icon.VolumeOff
                            } else {
                                FontAwesome.Icon.VolumeDown
                            }
                        }
                    }

                    Rectangle {
                        id : volumebar
                        anchors.horizontalCenter: parent.horizontalCenter
                        anchors.bottom: parent.top
                        //anchors.bottomMargin:3
                        color: "lightgray"
                        width: 17
                        height: 66
                        visible: false
                        radius: 5

                        Slider {
                            id: volumeslider
                            value: player.volume
                            minimumValue: 0.0
                            maximumValue: 1.0
                            stepSize: 0.001
                            anchors.centerIn: parent
                            orientation: Qt.Vertical
                            onPressedChanged: player.volume = value

                            style: SliderStyle {
                                groove: Item {
                                    implicitWidth: 47
                                    implicitHeight: 3
                                    anchors.centerIn: parent                                    

                                    Rectangle {
                                        antialiasing: true
                                        height: parent.height
                                        width: parent.width
                                        color: "gray"
                                        opacity: 0.8
                                        radius: 5

                                        Rectangle {
                                            antialiasing: true
                                            height: parent.height
                                            width: parent.width * control.value / control.maximumValue
                                            color: "red"
                                            radius: 5
                                        }
                                    }
                                }
                                handle: Rectangle {
                                    anchors.centerIn: parent
                                    color: control.pressed ? "white" : "lightgray"
                                    border.color: "gray"
                                    border.width: 1
                                    implicitWidth: 11
                                    implicitHeight: 11
                                    radius: 90
                                }
                            }
                        }
                    }

                    MouseArea {
                        anchors.fill: parent
                        onPressed: {
                            volumebar.visible = !volumebar.visible
                        }
                    }

                    MouseArea {
                        anchors.fill: volumebar
                        hoverEnabled: true
                        propagateComposedEvents: true

                        onClicked: mouse.accepted = false;
                        onPressed: mouse.accepted = false;
                        onReleased: mouse.accepted = false;
                        onDoubleClicked: mouse.accepted = false;
                        onPositionChanged: mouse.accepted = false;
                        onPressAndHold: mouse.accepted = false;

                        onExited: {
                            volumebar.visible = false
                        }
                    }

                }

                Text {
                    id: cog
                    font.pointSize: 17
                    font.family: "FontAwesome"
                    text: FontAwesome.Icon.Cog

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            settings.visible = !settings.visible
                            videos.visible = false
                            audios.visible = false
                            subtitles.visible = false


                        }
                    }
                }

                Text {
                    id : fullscreen
                    font.pointSize: 17
                    font.family: "FontAwesome"
                    text: FontAwesome.Icon.ResizeFull

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            if (window.visibility === Window.FullScreen) {
                                window.showNormal()
                                fullscreen.text = FontAwesome.Icon.ResizeFull
                            } else {
                                window.showFullScreen()
                                fullscreen.text = FontAwesome.Icon.ResizeSmall
                            }
                        }
                    }
                }
            }

            Item {
                width: playbar.width
                height: 5
                anchors.bottom: playbar.bottom

                Slider {
                    id: slider
                    maximumValue: player.duration
                    value: player.position
                    onPressedChanged: player.seek(value)
                    enabled: player.mediaInfo.seekable
                    anchors.bottom: parent.bottom
                    anchors.horizontalCenter: parent.horizontalCenter

                    MouseArea {
                        id: sliderMouseArea
                        anchors.fill: parent
                        hoverEnabled: true
                        propagateComposedEvents: true

                        onClicked: mouse.accepted = false;
                        onPressed: mouse.accepted = false;
                        onReleased: mouse.accepted = false;
                        onDoubleClicked: mouse.accepted = false;
                        onPositionChanged: mouse.accepted = false;
                        onPressAndHold: mouse.accepted = false;
                    }

                    Rectangle {
                        id: hoveredcliptime
                        width: 40
                        height: 17
                        color: "lightgray"
                        anchors.verticalCenter: parent.verticalCenter
                        visible: sliderMouseArea.containsMouse
                        x: sliderMouseArea.mouseX

                        Text {
                            font.pointSize: 13
                            color: "black"
                            anchors.centerIn: parent
                            text: {
                                var value = (sliderMouseArea.mouseX - slider.x) * player.duration / (slider.width - slider.x)
                                var date = new Date(Math.floor(value / 1e6));
                                date.getMinutes() + ":" + ('0' + date.getSeconds()).slice(-2)
                            }
                        }
                    }

                    style: SliderStyle {
                        groove: Item {
                            implicitWidth: playbar.width
                            implicitHeight: 5

                            Rectangle {
                                height: parent.height
                                width: parent.width
                                anchors.verticalCenter: parent.verticalCenter
                                color: "gray"
                                opacity: 0.8

                                Rectangle {
                                    antialiasing: true
                                    color: "red"
                                    height: parent.height
                                    width: parent.width * control.value / control.maximumValue
                                }

                                Rectangle {
                                    antialiasing: true
                                    color: "yellow"
                                    height: parent.height
                                    width: parent.width * player.buffering / 100
                                }
                            }
                        }
                        handle: Rectangle {
                            anchors.centerIn: parent
                            color: control.pressed ? "white" : "lightgray"
                            implicitWidth: 4
                            implicitHeight: 5
                        }
                    }
                }
            }
        }
    }
}