From d81680220d19a876ed3b8bb8e3e6412033ef83ae Mon Sep 17 00:00:00 2001 From: NamedKitten Date: Sun, 23 Dec 2018 14:52:31 +0000 Subject: [PATCH] [UI] Added a option to only seek on preview whilst paused. --- src/qml/UIComponents/VideoProgress.qml | 41 +++++++++++--- src/qml/main.qml | 74 ++++++++++++++++---------- 2 files changed, 78 insertions(+), 37 deletions(-) diff --git a/src/qml/UIComponents/VideoProgress.qml b/src/qml/UIComponents/VideoProgress.qml index 06ce831..66977a1 100644 --- a/src/qml/UIComponents/VideoProgress.qml +++ b/src/qml/UIComponents/VideoProgress.qml @@ -11,10 +11,18 @@ Slider { id: progressBar objectName: "progressBar" property string currentMediaURL: "" + property bool playing: false to: 1 value: 0.0 Connections { target: player + onPlayStatusChanged: function (status) { + if (status == Enums.PlayStatus.Playing) { + progressBar.playing = true + } else if (status == status == Enums.PlayStatus.Paused) { + progressBar.playing = false + } + } onPositionChanged: function (position) { if (!pressed) { progressBar.value = position @@ -62,14 +70,31 @@ Slider { z: 100 property string currentTime: "" - onEntered: progressBarTimePreview.visible = true - onExited: progressBarTimePreview.visible = false + onEntered: previewRect.visible = true + onExited: previewRect.visible = false onPositionChanged: { - var a = (progressBar.to / progressBar.availableWidth) * (mouseAreaProgressBar.mapToItem(progressBar, mouseAreaProgressBar.mouseX, 0).x - 2) - progressBarTimePreview.playerCommand(Enums.Commands.SeekAbsolute, a) - progressBarTimePreview.x = mouseAreaProgressBar.mapToItem(controlsOverlay, mouseAreaProgressBar.mouseX, 0).x - progressBarTimePreview.width / 2 - progressBarTimePreview.y = progressBackground.y - progressBarTimePreview.height - controlsBar.height * 2 + var a = (progressBar.to / progressBar.availableWidth) + * (mouseAreaProgressBar.mapToItem( + progressBar, mouseAreaProgressBar.mouseX, 0).x - 2) + var shouldSeek = false + if (!appearance.updatePreviewWhilstPlaying) { + if (!progressBar.playing) { + shouldSeek = true + } + } else { + shouldSeek = true + } + if (shouldSeek) { + progressBarTimePreview.playerCommand( + Enums.Commands.SeekAbsolute, a) + } else { + hoverProgressLabel.text = utils.createTimestamp(a) + } + previewRect.x = mouseAreaProgressBar.mapToItem( + controlsOverlay, mouseAreaProgressBar.mouseX, + 0).x - previewRect.width / 2 + previewRect.y = progressBackground.y - previewRect.height - controlsBar.height * 2 } } @@ -80,7 +105,8 @@ Slider { width: progressBar.availableWidth height: progressBar.getProgressBarHeight( fun.nyanCat, mouseAreaProgressBar.containsMouse) - color: getAppearanceValueForTheme(appearance.themeName,"progressBackgroundColor") + color: getAppearanceValueForTheme(appearance.themeName, + "progressBackgroundColor") ProgressBar { id: cachedLength @@ -137,7 +163,6 @@ Slider { } } - handle: Rectangle { z: 70 id: handleRect diff --git a/src/qml/main.qml b/src/qml/main.qml index b5813ad..f6904e6 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -23,7 +23,7 @@ Window { QMLDebugger { id: qmlDebugger } - + function getAppearanceValueForTheme(themeName, name) { if (themeName == "YouTube") { return youTubeAppearance[name] @@ -37,7 +37,7 @@ Window { Translator { id: translate } - + Settings { id: loggingSettings category: "Logging" @@ -46,7 +46,6 @@ Window { property bool logPreview: false } - Settings { id: backendSettings category: "Backend" @@ -58,6 +57,7 @@ Window { id: appearance category: "Appearance" property bool titleOnlyOnFullscreen: true + property bool updatePreviewWhilstPlaying: true property bool clickToPause: true property bool useMpvSubs: false property string themeName: "YouTube" @@ -176,15 +176,16 @@ Window { property int lastScreenVisibility function toggleFullscreen() { - console.error("a", mainWindow.visibility, Window.FullScreen, lastScreenVisibility) + console.error("a", mainWindow.visibility, Window.FullScreen, + lastScreenVisibility) if (mainWindow.visibility != Window.FullScreen) { lastScreenVisibility = mainWindow.visibility mainWindow.visibility = Window.FullScreen } else { mainWindow.visibility = lastScreenVisibility } - console.error("b", mainWindow.visibility, Window.FullScreen, lastScreenVisibility) - + console.error("b", mainWindow.visibility, Window.FullScreen, + lastScreenVisibility) } Utils { @@ -202,7 +203,11 @@ Window { onPlaylistChanged: function (playlist) { for (var thing in playlist) { var item = playlist[thing] - if (playlist[thing]["current"]) {progressBarTimePreview.playerCommand(Enums.Commands.LoadFile, String(playlist[thing]["filename"]))} + if (playlist[thing]["current"]) { + progressBarTimePreview.playerCommand( + Enums.Commands.LoadFile, + String(playlist[thing]["filename"])) + } progressBarTimePreview.playerCommand(Enums.Commands.ForcePause) } } @@ -377,7 +382,7 @@ Window { mouseAreaPlayerTimer.restart() } } - + Timer { id: statsUpdater interval: 1000 @@ -389,7 +394,7 @@ Window { } } } - + Text { id: statsForNerdsText text: "" @@ -410,10 +415,8 @@ Window { Component.onCompleted: { console.error(statsForNerdsText.lineHeight, font.pixelSize) } - } - MainMenu { id: menuBar visible: controlsOverlay.controlsShowing @@ -460,41 +463,54 @@ Window { ControlsBar { id: controlsBar - PlayerBackend { - id: progressBarTimePreview + Item { + id: previewRect height: 144 width: 256 z: 80 - visible: true - logging: loggingSettings.logPreview + visible: false - onDurationStringChanged: function (durationString) { - hoverProgressLabel.text = durationString - } - function startPlayer() { - update() - progressBarTimePreview.playerCommand(Enums.Commands.SetTrack, ["aid", "no"]) - progressBarTimePreview.playerCommand(Enums.Commands.SetTrack, ["sid", "no"]) - progressBarTimePreview.setOption("ytdl-format", "worstvideo[height<=?" + String(height) + "]/worst") - } - - Rectangle { + Rectangle { anchors.bottom: parent.bottom + anchors.right: parent.right width: hoverProgressLabel.width height: hoverProgressLabel.height - anchors.right: parent.right - color: getAppearanceValueForTheme(appearance.themeName, "mainBackground") + z: 100 + color: getAppearanceValueForTheme(appearance.themeName, + "mainBackground") Text { id: hoverProgressLabel text: "0:00" color: "white" - z: 90 font.family: appearance.fontName font.pixelSize: mainWindow.virtualHeight / 50 verticalAlignment: Text.AlignVCenter renderType: Text.NativeRendering } } + + PlayerBackend { + z: 90 + id: progressBarTimePreview + height: parent.height + width: parent.width + logging: loggingSettings.logPreview + + onDurationStringChanged: function (durationString) { + hoverProgressLabel.text = durationString + } + function startPlayer() { + update() + progressBarTimePreview.playerCommand( + Enums.Commands.SetTrack, ["aid", "no"]) + progressBarTimePreview.playerCommand( + Enums.Commands.SetTrack, ["sid", "no"]) + progressBarTimePreview.setOption( + "ytdl-format", + "worstvideo[height<=?" + String( + height) + "]/worst") + } + } } } }