~josephjamesmills/ubuntutv/pause_menu

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
import QtQuick 1.0
import QtMultimediaKit 1.1
import Effects 1.0
import "../common"
import "../sidebar"
import "../common/units.js" as Units
import "../common/utils.js" as Utils


AbstractPlayer {
    id: player
    property string uri
    property int category

    property variant nfo
    property int pressCount: 0
    property bool wasPlaying: false

    nfo: VideoInfo {
        uri: source
        //uri: preview.uri
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            if (sidebar.activeFocus) { sidebar.focus = false; player.forceActiveFocus() }
            else if (indicators.activeFocus) {indicators.focus = false; player.forceActiveFocus() }
            else if (!controls.focus) { controls.focus = true }
            else { controls.close() }
        }
    }

    VideoPlayerIndicatorsBar {
        id: indicators
        anchors.right: parent.right
        anchors.left: parent.left
        y: indicatorsVisibility.shown ? 0 : -height

        height: Units.tvPx(122)

        Keys.onPressed: {
            if (event.key == Qt.Key_Escape || event.key == Qt.Key_Backspace) {
                event.accepted = true
                focus = false
                player.forceActiveFocus()
            }
        }

        Keys.forwardTo: [indicatorsBehavior]
        onFocusedIndicatorChanged: indicatorsBehavior.restartTimer()

        Connections {
            target: indicators.focusedIndicator
            onActiveChanged: {
                if (indicators.focusedIndicator.active) indicatorsVisibility.beginForceVisible("indicators")
                else indicatorsVisibility.endForceVisible("indicators")
            }
        }
    }

    TimeoutBehavior {
        id: indicatorsBehavior
        target: indicators
        forcedVisible: indicatorsVisibility.forceVisible
    }

    VisibilityController {
        id: indicatorsVisibility
        behavior: indicatorsBehavior
        onShownChanged: if (!shown && indicators.activeFocus) {
                            indicators.focus = false
                            player.forceActiveFocus()
                        }
    }

    function playUri(uri) {
        source = uri
        play()
    }

    Keys.onPressed: {
        event.accepted = true
        if (event.key == Qt.Key_Left || event.key == Qt.Key_Right && !event.modifiers) {
            controls.focus = true
            if (event.isAutoRepeat) {
                pressCount += 1
            } else {
                wasPlaying = player.playing
                pressCount = 1
            }
        } else if (!event.isAutoRepeat && ((event.key == Qt.Key_MediaStop || event.key == Qt.Key_Escape ||
                                            event.key == Qt.Key_Backspace) && !event.modifiers) || (event.key == Qt.Key_S && event.modifiers & Qt.ControlModifier)) {
            if (player.scrubbing) player.play()
            else player.stop()
        } else if (!event.isAutoRepeat && event.key == Qt.Key_Return && !event.modifiers) {
            controls.focus = true
        } else if (!event.isAutoRepeat && event.key == Qt.Key_P && event.modifiers & Qt.ControlModifier) {
            if (player.playing) {
                controls.focus = true
                player.pause()
            } else player.play()
        } else if (!event.isAutoRepeat && event.key == Qt.Key_B && event.modifiers & Qt.ShiftModifier) {
            player.rewind()
        } else if (!event.isAutoRepeat && event.key == Qt.Key_F && event.modifiers & Qt.ShiftModifier) {
            player.fastForward()
        } else if (!event.isAutoRepeat && event.key == Qt.Key_B && event.modifiers & Qt.ControlModifier) {
            controls.previous()
        } else if (!event.isAutoRepeat && event.key == Qt.Key_F && event.modifiers & Qt.ControlModifier) {
            controls.next()
        } else {
            event.accepted = false
        }
    }

    function edgeEvent(event) {
        if (event.key == Qt.Key_F3 || event.key == Qt.Key_MediaPlay) {
            if (!sidebar.activeFocus) {
                sidebar.forceActiveFocus()
            } else {
                sidebar.focus = false
                player.forceActiveFocus()
            }
            event.accepted = true
        } else if (!event.isAutoRepeat && (event.key == Qt.Key_F2 || event.key == Qt.Key_Period ||
                                           (event.key == Qt.Key_R && event.modifiers & Qt.ControlModifier))) {
            if (!indicators.activeFocus) {
                indicators.forceActiveFocus()
            } else {
                indicators.focus = false
                player.forceActiveFocus()
            }
            event.accepted = true
        }
    }

    Keys.onReleased: {
        if (event.key == Qt.Key_Left || event.key == Qt.Key_Right) {
            event.accepted = true
            if (!event.isAutoRepeat && pressCount == 1) {
                if (event.key == Qt.Key_Left) {
                    player.seekBackward()
                } else {
                    player.seekForward()
                }
            } else if (!event.isAutoRepeat) {
                if (wasPlaying) player.play()
                else player.pause()
            } else if ((event.isAutoRepeat && pressCount == 1) || ((pressCount % 30) == 0)) {
                if (event.key == Qt.Key_Left) {
                    player.rewind()
                } else {
                    player.fastForward()
                }
            }
        }
    }

    Controls {
        id: controls
        anchors.left: parent.left; anchors.right: parent.right
        y: controlsVisibility.shown ? parent.height - height : parent.height
        shown: controlsVisibility.shown

        Behavior on y { NumberAnimation {} }

        state: player.state
        video: player.video

        function close() {
            if (player.paused) controlsVisibility.endForceVisible("pause")
            button.focus = true
            focus = false
            player.forceActiveFocus()
        }

        Keys.onPressed: {
            if (event.key == Qt.Key_Escape || event.key == Qt.Key_Backspace) {
                event.accepted = true
                close()
            }
        }

        Keys.forwardTo: [controlsBehavior]

        onButtonClicked: {
            if (["paused", "playing"].indexOf(state) != -1) player.togglePause()
            else player.play()
        }

        onClicked: {
            controlsBehavior.restartTimer()
        }

        onActiveFocusChanged: {
            if (!activeFocus && player.paused) controlsVisibility.endForceVisible("pause")
        }
    }
    Column {
        id: playertxtcolumn

        //anchors.left: parent.left
        //anchors.leftMargin: Units.tvPx(-70)
        //anchors.top: parent.top
        width: Units.tvPx(900)
    }
    TextCustom {
        id: title
        anchors.fill: playertxtcolumn
        anchors.centerIn: parent.Top
        anchors.top: parent.top
        anchors.topMargin: Units.tvPx(40)
        anchors.left: parent.left
        anchors.leftMargin: Units.tvPx(440)
        anchors.verticalCenterOffset: -controls.height / 2
        //wrapMode: Text.Wrap  //"WrapAtWordBoundaryOrAnywhere"//pausetxtbasckground
        opacity: player.paused ? 1 : 0

        Behavior on opacity { NumberAnimation {} }

        fontSize: "xxx-large"
        color: "white"

        effect: DropShadow {
            blurRadius: 3
            offset.x: 0
            offset.y: 1
            color: "#1e1e1e"
        }

        elide: {
            if (player.nfo.video || video.metaData.title !== undefined) return Text.ElideMiddle
            else return Text.ElideLeft
        }
        text: {
            if (player.nfo.video) return player.nfo.video.title
            else if (video.metaData.title !== undefined) return video.metaData.title
            else return video.source.toString().replace(/.*\//, '')
        }

                                                        BorderImage {
                                                        id: pausetxtbasckground
                                                        source: "../dash/artwork/search_background.png"
                                                        anchors.left: parent.left
                                                        anchors.leftMargin: Units.tvPx(-440)
                                                        anchors.top: parent.top
                                                        anchors.topMargin: Units.tvPx(-40)
                                                        opacity: player.paused ? 1 : .75
                                                        Behavior on opacity { NumberAnimation {} }
                                                        width: Units.tvPx(1280); height: Units.tvPx(668)
                                                        border.left:+  40; border.top: 40
                                                        border.right: 40; border.bottom: 40
        }

                                                        BorderImage {
                                                        id: previewImageDropShadow
                                                        source: "../dash/artwork/video_preview_shadow.sci"
                                                        anchors.fill: previewImage
                                                        anchors.margins: -Units.tvPx(15)
        }

                                                        PlayerPreviewImageBox {
                                                        id: previewImage
                                                        //                        property variant imageSourceUrl: imageSource
                                                        anchors.centerIn: parent.Top
                                                        anchors.left: parent.left
                                                        anchors.top: parent.top
                                                        anchors.topMargin: Units.tvPx(40)
                                                        anchors.leftMargin: Units.tvPx(-415)
                                                        color: "#2C001E"
                                                        showBackgroundImage: false
                                                        showBlackBoundary: false

                                                        source: Utils.removeExt(uri) + ((nfo.isMovie) ? "-fanart.jpg" : ".tbn")
                                                        //source: //imageSourceUrl
                                                        width: Units.tvPx(320); height: Units.tvPx(368)
                                                        opacity: .75
                                                        Behavior on opacity { NumberAnimation {} }
        }

                                                        PlayerRatingStars {
                                                        id: rating
                                                        anchors.top:  parent.top
                                                        anchors.topMargin: Units.tvPx(100)
                                                        rating: (nfo.video) ? nfo.video.rating * 0.5 : 0.0
                                                        spacing: Units.tvPx(42)
                                                        starIconSize: 60

        }
                                                        BorderImage {
                                                        id: pausextratxtbasckground
                                                        //anchors.fill: playercolumn
                                                        source: "../dash/artwork/search_background.png"
                                                        anchors.left: parent.left
                                                        anchors.leftMargin: Units.tvPx(-70)
                                                        anchors.top: parent.top
                                                        anchors.topMargin: Units.tvPx(170)
                                                        opacity: player.paused ? 1 : 0
                                                        Behavior on opacity { NumberAnimation {} }
                                                        width: Units.tvPx(900); height: Units.tvPx(450)
                                                        border.left:+  40; border.top: 40
                                                        border.right: 40; border.bottom: 40
        }


                                                        Column {
                                                        id: playercolumn

                                                        anchors.left: parent.left
                                                        anchors.leftMargin: Units.tvPx(-70)
                                                        anchors.top: parent.top
                                                        anchors.topMargin: Units.tvPx(170)
                                                        width: Units.tvPx(901);
                                                        height: Units.tvPx(350)



        }

                                                        Text {
                                                        id: playertitleExtraInfo
                                                        anchors.fill: playercolumn
                                                        //anchors.left: parent.left
                                                        //anchors.leftMargin: Units.tvPx(0)
                                                        anchors.top: parent.top
                                                        wrapMode: Text.WordWrap
                                                        //elide: Text.ElideMiddle
                                                        //maximumLineCount: 9
                                                        // fontSize: "large"
                                                        color: "white"
                                                        opacity: player.paused ? 1 : 0
                                                        // Behavior on opacity { NumberAnimation {} }
                                                        property string baseTitleMovie: u2d.tr('(%1 %4)')
                                                        property string baseTitleTV: u2d.tr('(%1 %2x%3 %4)')


                                                        text: {
                                                        if (nfo.video && nfo.isMovie) {
                                                        return "" //baseTitleMovie.arg(nfo.video.year)
        } else if (nfo.video && nfo.tvShow) {
                                                        return baseTitleTV.arg(nfo.tvShow.title).arg(nfo.video.season).arg(nfo.video.episode)
        } else {
                                                        return ""
        }
        }


                                                        Text {
                                                        id: playerdetails
                                                        anchors.fill: playercolumn
                                                        anchors.top: parent.top
                                                        anchors.topMargin: Units.tvPx(12)
                                                        anchors.left: parent.left
                                                        anchors.leftMargin: Units.tvPx(14)
                                                        anchors.right: parent.right
                                                        anchors.rightMargin: Units.tvPx(14)
                                                        //width: Units.tvPx(200)


                                                        //width: playercolumn.width
                                                        //height: playertxtcolumn.height
                                                        // maximumLineCount : 2
                                                        font.pixelSize: 33
                                                        wrapMode: Text.WordWrap
                                                        color: "white"

                                                        property string baseText: u2d.tr("%1<br>"+""+"<b>Director:</b>%2<br>"+""+"<b>Cast:</b>%3")

                                                        text:(nfo.video) ? baseText.arg((nfo.video.plot) ? nfo.video.plot : "")
                                                                           .arg((nfo.video.director) ? nfo.video.director : "")
                                                                           .arg(nfo.getActors().join(", ")) : "".arg((nfo.video.premiered) ? nfo.video.premiered : "")


        }
        }
        }




                                                        VisibilityController {
                                                        id: controlsVisibility
                                                        behavior: controlsBehavior
                                                        onShownChanged: if (!shown && controls.activeFocus) {
                                                        controls.focus = false
                                                        player.forceActiveFocus()
        }

                                                        Connections {
                                                        target: player
                                                        onPausedChanged:
                                                        if (player.paused) controlsVisibility.beginForceVisible("pause")
                                                        else controlsVisibility.endForceVisible("pause")
        }
        }

                                                        TimeoutBehavior {
                                                        id: controlsBehavior
                                                        target: controls
                                                        forcedVisible: controlsVisibility.forceVisible
        }

                                                        Sidebar {
                                                        id: sidebar
                                                        source: "../player/VideoSidebar.qml"
                                                        anchors.top: parent.top
                                                        anchors.bottom: parent.bottom
                                                        width: Units.tvPx(550) + borderWidth
                                                        x: sidebarVisibility.shown ? parent.width - width : parent.width

                                                        Behavior on x { NumberAnimation { duration: 125 } }

                                                        Keys.onPressed: {
                                                        if (event.key == Qt.Key_Escape || event.key == Qt.Key_Backspace) {
                                                        event.accepted = true
                                                        focus = false
                                                        player.forceActiveFocus()

        }
        }

                                                        onLoaded: item.video = player.video
        }

                                                        VisibilityController {
                                                        id: sidebarVisibility
                                                        behavior: ImmediateHideBehavior {
                                                        target: sidebar
        }
                                                        onShownChanged: if (!shown && sidebar.activeFocus) {
                                                        sidebar.focus = false
                                                        player.forceActiveFocus()
        }
        }

                                                        onStatusChanged: {
                                                        if (status == Video.EndOfMedia) {
                                                        stop()
        }
        }

                                                        onActiveFocusChanged: {
                                                        if (!activeFocus) {
                                                        controls.focus = false
                                                        sidebar.focus = false
                                                        indicators.focus = false
        }
        }
        }