1
0
Fork 0

[UI] Moved PlaylistDialog into it's own file.

This commit is contained in:
NamedKitten 2018-11-23 08:19:28 +00:00
parent afba6a63d2
commit 37158fbcad
9 changed files with 416 additions and 372 deletions

5
format-code.sh Executable file
View file

@ -0,0 +1,5 @@
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
pushd $SOURCE_DIR
qmlfmt -w src/qml/*.qml
clang-format -style mozilla -i src/*
popd

View file

@ -435,7 +435,8 @@ DirectMpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
case Enums::Commands::SetPlaylistPos: { case Enums::Commands::SetPlaylistPos: {
command(QVariantList() << "set" << "playlist-pos" << args); command(QVariantList() << "set"
<< "playlist-pos" << args);
break; break;
} }

View file

@ -425,7 +425,8 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
case Enums::Commands::SetPlaylistPos: { case Enums::Commands::SetPlaylistPos: {
command(QVariantList() << "set" << "playlist-pos" << args); command(QVariantList() << "set"
<< "playlist-pos" << args);
break; break;
} }

View file

@ -66,7 +66,6 @@ signals:
void audioDevicesChanged(); void audioDevicesChanged();
void playlistChanged(); void playlistChanged();
private slots: private slots:
void doUpdate(); void doUpdate();
void on_mpv_events(); void on_mpv_events();

View file

@ -68,7 +68,7 @@ Item {
height: subsContainer.childrenRect.height height: subsContainer.childrenRect.height
} }
Component.onCompleted: { Component.onCompleted: {
player.subtitlesChanged.connect(function(subtitles) { player.subtitlesChanged.connect(function (subtitles) {
text = subtitles text = subtitles
}) })
} }
@ -79,7 +79,9 @@ Item {
Rectangle { Rectangle {
id: controlsBackground id: controlsBackground
height: controlsBar.visible ? controlsBar.height + (fun.nyanCat ? progressBackground.height * 0.3: progressBackground.height * 2) : 0 height: controlsBar.visible ? controlsBar.height
+ (fun.nyanCat ? progressBackground.height
* 0.3 : progressBackground.height * 2) : 0
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
@ -111,13 +113,15 @@ Item {
anchors.topMargin: progressBackground.height anchors.topMargin: progressBackground.height
bottomPadding: 0 bottomPadding: 0
Component.onCompleted: { Component.onCompleted: {
player.positionChanged.connect(function(position) { player.positionChanged.connect(function (position) {
if (! pressed) {progressBar.value = position} if (!pressed) {
progressBar.value = position
}
}) })
player.durationChanged.connect(function(duration) { player.durationChanged.connect(function (duration) {
progressBar.to = duration progressBar.to = duration
}) })
player.cachedDurationChanged.connect(function(duration) { player.cachedDurationChanged.connect(function (duration) {
cachedLength.value = progressBar.value + duration cachedLength.value = progressBar.value + duration
}) })
} }
@ -153,7 +157,8 @@ Item {
color: appearance.progressBackgroundColor color: appearance.progressBackgroundColor
ProgressBar { ProgressBar {
id: cachedLength id: cachedLength
background: Item {} background: Item {
}
contentItem: Item { contentItem: Item {
Rectangle { Rectangle {
width: cachedLength.visualPosition * parent.width width: cachedLength.visualPosition * parent.width
@ -174,10 +179,12 @@ Item {
value: progressBar.value value: progressBar.value
opacity: 1 opacity: 1
anchors.leftMargin: 0 anchors.leftMargin: 0
background: Item {} background: Item {
}
contentItem: Item { contentItem: Item {
Rectangle { Rectangle {
width: progressLength.visualPosition * parent.width + progressBar.handle.width / 2 width: progressLength.visualPosition * parent.width
+ progressBar.handle.width / 2
height: parent.height height: parent.height
color: appearance.progressSliderColor color: appearance.progressSliderColor
Image { Image {
@ -217,12 +224,11 @@ Item {
} }
} }
RowLayout { RowLayout {
id: layout id: layout
anchors.fill: parent anchors.fill: parent
spacing: 2 spacing: 2
Button { Button {
id: playlistPrevButton id: playlistPrevButton
objectName: "playlistPrevButton" objectName: "playlistPrevButton"
@ -234,10 +240,11 @@ RowLayout {
onClicked: { onClicked: {
player.playerCommand(Enums.Commands.PreviousPlaylistItem) player.playerCommand(Enums.Commands.PreviousPlaylistItem)
} }
background: Item {} background: Item {
}
Component.onCompleted: { Component.onCompleted: {
player.playlistPositionChanged.connect(function(position) { player.playlistPositionChanged.connect(function (position) {
if (position != 0 ) { if (position != 0) {
visible = true visible = true
} else { } else {
visible = false visible = false
@ -254,9 +261,10 @@ RowLayout {
onClicked: { onClicked: {
player.playerCommand(Enums.Commands.TogglePlayPause) player.playerCommand(Enums.Commands.TogglePlayPause)
} }
background: Item {} background: Item {
}
Component.onCompleted: { Component.onCompleted: {
player.playStatusChanged.connect(function(status) { player.playStatusChanged.connect(function (status) {
if (status == Enums.PlayStatus.Playing) { if (status == Enums.PlayStatus.Playing) {
icon.source = "qrc:/player/icons/pause.svg" icon.source = "qrc:/player/icons/pause.svg"
} else if (status == Enums.PlayStatus.Paused) { } else if (status == Enums.PlayStatus.Paused) {
@ -275,7 +283,8 @@ RowLayout {
onClicked: { onClicked: {
player.playerCommand(Enums.Commands.NextPlaylistItem) player.playerCommand(Enums.Commands.NextPlaylistItem)
} }
background: Item {} background: Item {
}
} }
Button { Button {
@ -287,9 +296,10 @@ RowLayout {
onClicked: { onClicked: {
player.playerCommand(Enums.Commands.ToggleMute) player.playerCommand(Enums.Commands.ToggleMute)
} }
background: Item {} background: Item {
}
Component.onCompleted: { Component.onCompleted: {
player.volumeStatusChanged.connect(function(status) { player.volumeStatusChanged.connect(function (status) {
if (status == Enums.VolumeStatus.Muted) { if (status == Enums.VolumeStatus.Muted) {
volumeButton.icon.source = "qrc:/player/icons/volume-mute.svg" volumeButton.icon.source = "qrc:/player/icons/volume-mute.svg"
} else if (status == Enums.VolumeStatus.Low) { } else if (status == Enums.VolumeStatus.Low) {
@ -315,10 +325,11 @@ RowLayout {
(handle ? handle.implicitHeight : 0) (handle ? handle.implicitHeight : 0)
+ topPadding + bottomPadding) + topPadding + bottomPadding)
onMoved: { onMoved: {
player.playerCommand(Enums.Commands.SetVolume, Math.round(volumeBar.value).toString()) player.playerCommand(Enums.Commands.SetVolume,
Math.round(volumeBar.value).toString())
} }
Component.onCompleted: { Component.onCompleted: {
player.volumeChanged.connect(function(volume) { player.volumeChanged.connect(function (volume) {
volumeBar.value = volume volumeBar.value = volume
}) })
} }
@ -360,7 +371,8 @@ RowLayout {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
renderType: Text.NativeRendering renderType: Text.NativeRendering
Component.onCompleted: { Component.onCompleted: {
player.durationStringChanged.connect(function(durationString) { player.durationStringChanged.connect(
function (durationString) {
text = durationString text = durationString
}) })
} }
@ -380,7 +392,8 @@ RowLayout {
onClicked: { onClicked: {
console.log("Settings Menu Not Yet Implemented.") console.log("Settings Menu Not Yet Implemented.")
} }
background: Item {} background: Item {
}
} }
Button { Button {
@ -395,8 +408,9 @@ RowLayout {
toggleFullscreen() toggleFullscreen()
} }
background: Item {} background: Item {
} }
} }
}
} }
} }

View file

@ -14,7 +14,9 @@ MenuBar {
height: Screen.height / 32 height: Screen.height / 32
function anythingOpen() { function anythingOpen() {
for (var i = 0, len = menuBar.count; i < len; i++) { for (var i = 0, len = menuBar.count; i < len; i++) {
if (menuBar.menuAt(i).opened) { return true } if (menuBar.menuAt(i).opened) {
return true
}
} }
} }
@ -101,7 +103,8 @@ MenuBar {
title: translate.getTranslation("OPEN_FILE", i18n.language) title: translate.getTranslation("OPEN_FILE", i18n.language)
nameFilters: ["All files (*)"] nameFilters: ["All files (*)"]
onAccepted: { onAccepted: {
player.playerCommand(Enums.Commands.LoadFile, String(fileDialog.file)) player.playerCommand(Enums.Commands.LoadFile,
String(fileDialog.file))
fileDialog.close() fileDialog.close()
} }
onRejected: { onRejected: {
@ -124,87 +127,8 @@ MenuBar {
} }
} }
Dialog { PlaylistDialog {
id: playlistDialog id: playlistDialog
title: "Playlist"
height: 480
width: 720
modality: Qt.NonModal
onAccepted: {
console.log("ok")
}
Component.onCompleted: {
player.titleChanged.connect(updatePlaylistMenu)
player.playlistChanged.connect(updatePlaylistMenu)
}
function updatePlaylistMenu() {
var playlist = player.playerCommand(Enums.Commands.GetPlaylist)
playlistModel.clear()
for (var thing in playlist) {
var item = playlist[thing]
playlistModel.append({
"playlistItemTitle": item["title"],
"playlistItemFilename": item["filename"],
"current": item["current"],
"playlistPos": thing
})
}
}
Component {
id: playlistDelegate
Item {
id: playlistItem
width: playlistDialog.width; height: 0
Button {
height: parent.height
id: playlistItemButton
font.pixelSize: 12
contentItem: Text {
id: playlistItemText
font: parent.font
color: "white"
text: playlistItemButton.text
height: parent.height
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
onClicked: {
player.playerCommand(Enums.Commands.SetPlaylistPos, playlistPos)
}
background: Rectangle { color: current ? "orange" : "transparent" }
}
Component.onCompleted: {
var itemText = ""
if (typeof playlistItemTitle !== "undefined") {
itemText += '<b>Title:</b> ' + playlistItemTitle + "<br>"
playlistItem.height += 30
}
if (typeof playlistItemFilename !== "undefined") {
itemText += '<b>Filename:</b> ' + playlistItemFilename + "<br>"
playlistItem.height += 30
}
playlistItemText.text = itemText
}
}
}
ListView {
id: playlistListView
anchors.fill: parent
model: ListModel { id: playlistModel }
delegate: playlistDelegate
highlight: Item {}
focus: true
}
} }
delegate: MenuBarItem { delegate: MenuBarItem {
@ -423,7 +347,8 @@ MenuBar {
player.audioDevicesChanged.connect(updateAudioDevices) player.audioDevicesChanged.connect(updateAudioDevices)
} }
function updateAudioDevices() { function updateAudioDevices() {
var audioDevices = player.playerCommand(Enums.Commands.GetAudioDevices) var audioDevices = player.playerCommand(
Enums.Commands.GetAudioDevices)
for (var i = 0, len = audioDeviceMenu.count; i < len; i++) { for (var i = 0, len = audioDeviceMenu.count; i < len; i++) {
audioDeviceMenu.takeAction(0) audioDeviceMenu.takeAction(0)
@ -564,8 +489,7 @@ MenuBar {
} }
} }
Action { Action {
text: translate.getTranslation("PLAYLIST_MENU", text: translate.getTranslation("PLAYLIST_MENU", i18n.language)
i18n.language)
onTriggered: { onTriggered: {
playlistDialog.open() playlistDialog.open()
} }

View file

@ -0,0 +1,91 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Dialogs 1.3
import QtQuick.Window 2.11
import Qt.labs.settings 1.0
import Qt.labs.platform 1.0 as LabsPlatform
import player 1.0
Dialog {
id: playlistDialog
title: "Playlist"
height: Math.max(480, childrenRect.height * playlistListView.count)
width: 720
modality: Qt.NonModal
Component.onCompleted: {
player.titleChanged.connect(updatePlaylistMenu)
player.playlistChanged.connect(updatePlaylistMenu)
}
function updatePlaylistMenu() {
var playlist = player.playerCommand(Enums.Commands.GetPlaylist)
playlistModel.clear()
for (var thing in playlist) {
var item = playlist[thing]
playlistModel.append({
playlistItemTitle: item["title"],
playlistItemFilename: item["filename"],
current: item["current"],
playlistPos: thing
})
}
}
Component {
id: playlistDelegate
Item {
id: playlistItem
width: playlistDialog.width
height: childrenRect.height
Button {
width: parent.width
id: playlistItemButton
font.pixelSize: 12
padding: 0
bottomPadding: 0
contentItem: Text {
id: playlistItemText
font: parent.font
bottomPadding: 0
color: "white"
text: playlistItemButton.text
height: parent.height
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
wrapMode: Text.Wrap
}
onClicked: {
player.playerCommand(Enums.Commands.SetPlaylistPos,
playlistPos)
}
background: Rectangle {
color: current ? "orange" : "transparent"
}
}
Component.onCompleted: {
var itemText = ""
if (typeof playlistItemTitle !== "undefined") {
itemText += '<b>Title:</b> ' + playlistItemTitle + "<br>"
}
if (typeof playlistItemFilename !== "undefined") {
itemText += '<b>Filename:</b> ' + playlistItemFilename
}
playlistItemText.text = itemText
}
}
}
ListView {
id: playlistListView
anchors.fill: parent
model: ListModel {
id: playlistModel
}
delegate: playlistDelegate
highlight: Item {
}
focus: true
}
}

View file

@ -98,7 +98,6 @@ ApplicationWindow {
property string customKeybind9Command: "" property string customKeybind9Command: ""
} }
property int lastScreenVisibility property int lastScreenVisibility
function toggleFullscreen() { function toggleFullscreen() {
@ -120,7 +119,7 @@ ApplicationWindow {
function startPlayer() { function startPlayer() {
console.log(player) console.log(player)
console.log(typeof(player)) console.log(typeof (player))
var args = Qt.application.arguments var args = Qt.application.arguments
var len = Qt.application.arguments.length var len = Qt.application.arguments.length
var argNo = 0 var argNo = 0
@ -149,18 +148,24 @@ ApplicationWindow {
argument = argument.substr(2) argument = argument.substr(2)
if (argument.length > 0) { if (argument.length > 0) {
var splitArg = argument.split(/=(.+)/) var splitArg = argument.split(/=(.+)/)
if (splitArg[0] == "screen" || splitArg[0] == "fs-screen") { if (splitArg[0] == "screen"
|| splitArg[0] == "fs-screen") {
for (var i = 0, len = Qt.application.screens.length; i < len; i++) { for (var i = 0, len = Qt.application.screens.length; i < len; i++) {
var screen = Qt.application.screens[i]; var screen = Qt.application.screens[i]
console.log("Screen Name: " + screen["name"] + " Screen Number: " + String(i)) console.log("Screen Name: " + screen["name"]
if (screen["name"] == splitArg[1] || String(i) == splitArg[1] ) { + " Screen Number: " + String(
i))
if (screen["name"] == splitArg[1] || String(
i) == splitArg[1]) {
console.log("Switching to screen: " + screen["name"]) console.log("Switching to screen: " + screen["name"])
mainWindow.screen = screen mainWindow.screen = screen
mainWindow.width = mainWindow.screen.width / 2 mainWindow.width = mainWindow.screen.width / 2
mainWindow.height = mainWindow.screen.height / 2 mainWindow.height = mainWindow.screen.height / 2
mainWindow.x = mainWindow.screen.virtualX + mainWindow.width / 2 mainWindow.x = mainWindow.screen.virtualX
mainWindow.y = mainWindow.screen.virtualY + mainWindow.height / 2 + mainWindow.width / 2
if (splitArg[0] == "fs-screen" ) { mainWindow.y = mainWindow.screen.virtualY
+ mainWindow.height / 2
if (splitArg[0] == "fs-screen") {
toggleFullscreen() toggleFullscreen()
} }
continue continue
@ -170,16 +175,17 @@ ApplicationWindow {
} }
if (splitArg[0] == "fullscreen") { if (splitArg[0] == "fullscreen") {
toggleFullscreen() toggleFullscreen()
continue; continue
} }
if (splitArg[1] == undefined || splitArg[1].length == 0) { if (splitArg[1] == undefined
|| splitArg[1].length == 0) {
splitArg[1] = "yes" splitArg[1] = "yes"
} }
player.setOption(splitArg[0], splitArg[1]) player.setOption(splitArg[0], splitArg[1])
} }
} else { } else {
player.playerCommand(Enums.Commands.AppendFile, argument) player.playerCommand(Enums.Commands.AppendFile,
argument)
} }
} }
} }
@ -198,7 +204,6 @@ ApplicationWindow {
mouseAreaPlayer.cursorShape = Qt.ArrowCursor mouseAreaPlayer.cursorShape = Qt.ArrowCursor
} }
} }
} }
Item { Item {
anchors.centerIn: player anchors.centerIn: player
@ -239,7 +244,9 @@ ApplicationWindow {
} }
Action { Action {
onTriggered: { onTriggered: {
if (mainWindow.visibility == Window.FullScreen) {toggleFullscreen()} if (mainWindow.visibility == Window.FullScreen) {
toggleFullscreen()
}
} }
shortcut: "Esc" shortcut: "Esc"
} }
@ -259,7 +266,7 @@ ApplicationWindow {
} }
Timer { Timer {
id: mouseAreaPlayerTimer id: mouseAreaPlayerTimer
interval: 2000 interval: 1000
running: true running: true
repeat: false repeat: false
onTriggered: { onTriggered: {
@ -272,7 +279,6 @@ ApplicationWindow {
} }
} }
MainMenu { MainMenu {
id: menuBar id: menuBar
visible: player.controlsShowing visible: player.controlsShowing
@ -305,9 +311,11 @@ ApplicationWindow {
font.pixelSize: 14 font.pixelSize: 14
font.bold: true font.bold: true
opacity: 1 opacity: 1
visible: player.controlsShowing && ((!appearance.titleOnlyOnFullscreen) || (mainWindow.visibility == Window.FullScreen) ) visible: player.controlsShowing
&& ((!appearance.titleOnlyOnFullscreen)
|| (mainWindow.visibility == Window.FullScreen))
Component.onCompleted: { Component.onCompleted: {
player.titleChanged.connect(function(title) { player.titleChanged.connect(function (title) {
text = title text = title
}) })
} }

View file

@ -1,6 +1,7 @@
<RCC> <RCC>
<qresource prefix="/player"> <qresource prefix="/player">
<file>main.qml</file> <file>main.qml</file>
<file>PlaylistDialog.qml</file>
<file>CustomComboBox.qml</file> <file>CustomComboBox.qml</file>
<file>CustomMenuItem.qml</file> <file>CustomMenuItem.qml</file>
<file>CustomMenu.qml</file> <file>CustomMenu.qml</file>