1
0
Fork 0

[QML] Reformatted code.

This commit is contained in:
Kitteh 2018-10-24 19:49:05 +01:00
parent 59110f590a
commit 8fbe73a718
3 changed files with 443 additions and 402 deletions

View file

@ -27,13 +27,13 @@ ComboBox {
} }
onPaint: { onPaint: {
context.reset(); context.reset()
context.moveTo(0, 0); context.moveTo(0, 0)
context.lineTo(width, 0); context.lineTo(width, 0)
context.lineTo(width / 2, height); context.lineTo(width / 2, height)
context.closePath(); context.closePath()
context.fillStyle = control.pressed ? "#17a81a" : "#21be2b"; context.fillStyle = control.pressed ? "#17a81a" : "#21be2b"
context.fill(); context.fill()
} }
} }
@ -66,9 +66,13 @@ ComboBox {
implicitHeight: contentHeight implicitHeight: contentHeight
model: control.popup.visible ? control.delegateModel : null model: control.popup.visible ? control.delegateModel : null
currentIndex: control.highlightedIndex currentIndex: control.highlightedIndex
highlight: Rectangle { color: "white"; opacity: 1; } highlight: Rectangle {
color: "white"
opacity: 1
}
ScrollIndicator.vertical: ScrollIndicator { } ScrollIndicator.vertical: ScrollIndicator {
}
} }
background: Rectangle { background: Rectangle {

View file

@ -5,29 +5,29 @@ import QtQuick.Layouts 1.11
import QtQuick.Window 2.11 import QtQuick.Window 2.11
MenuItem { MenuItem {
FontLoader { FontLoader {
id: notoFont id: notoFont
source: "fonts/NotoSans.ttf" source: "fonts/NotoSans.ttf"
}
id: menuItem
implicitWidth: 100
implicitHeight: 20
contentItem: Text {
rightPadding: menuItem.arrow.width
text: menuItem.text
font.family: notoFont.name
opacity: 1
color: menuItem.highlighted ? "#5a50da" : "white"
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 200
implicitHeight: 20
opacity: 1
color: menuItem.highlighted ? "#c0c0f0" : "transparent"
}
} }
id: menuItem
implicitWidth: 100
implicitHeight: 20
contentItem: Text {
rightPadding: menuItem.arrow.width
text: menuItem.text
font.family: notoFont.name
opacity: 1
color: menuItem.highlighted ? "#5a50da" : "white"
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 200
implicitHeight: 20
opacity: 1
color: menuItem.highlighted ? "#c0c0f0" : "transparent"
}
}

View file

@ -91,8 +91,7 @@ ApplicationWindow {
console.log("Updating Track Menu, Total Tracks: " + tracks) console.log("Updating Track Menu, Total Tracks: " + tracks)
for (track = 0; track <= tracks; track++) { for (track = 0; track <= tracks; track++) {
var trackID = player.getProperty("track-list/" + track + "/id") var trackID = player.getProperty("track-list/" + track + "/id")
var trackType = player.getProperty( var trackType = player.getProperty("track-list/" + track + "/type")
"track-list/" + track + "/type")
var trackLang = LanguageCodes.localeCodeToEnglish( var trackLang = LanguageCodes.localeCodeToEnglish(
String(player.getProperty( String(player.getProperty(
"track-list/" + track + "/lang"))) "track-list/" + track + "/lang")))
@ -137,23 +136,27 @@ ApplicationWindow {
id: initTimer id: initTimer
interval: 1000 interval: 1000
running: false running: false
repeat: false repeat: false
onTriggered: { onTriggered: {
player.startPlayer() player.startPlayer()
} }
} }
Component.onCompleted: { initTimer.start() } Component.onCompleted: {
initTimer.start()
}
function startPlayer() { function startPlayer() {
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
player.setOption("ytdl-format", "bestvideo[width<=" + Screen.width player.setOption("ytdl-format", "bestvideo[width<=" + Screen.width
+ "][height<=" + Screen.height + "]+bestaudio") + "][height<=" + Screen.height + "]+bestaudio")
if (len > 1) { if (len > 1) {
for (argNo = 1; argNo < len; argNo++) { for (argNo = 1; argNo < len; argNo++) {
var argument = args[argNo] var argument = args[argNo]
if (argument.indexOf("KittehPlayer") !== -1) { continue; } if (argument.indexOf("KittehPlayer") !== -1) {
continue
}
if (argument.startsWith("--")) { if (argument.startsWith("--")) {
argument = argument.substr(2) argument = argument.substr(2)
if (argument.length > 0) { if (argument.length > 0) {
@ -215,12 +218,14 @@ ApplicationWindow {
} }
function isAnyMenuOpen() { function isAnyMenuOpen() {
return subtitlesMenu.visible || settingsMenu.visible || fileMenuBarItem.opened || playbackMenuBarItem.opened || viewMenuBarItem.opened || tracksMenuBarItem.opened return subtitlesMenu.visible || settingsMenu.visible
|| fileMenuBarItem.opened || playbackMenuBarItem.opened
|| viewMenuBarItem.opened || tracksMenuBarItem.opened
} }
function hideControls() { function hideControls() {
if ( ! isAnyMenuOpen() ) { if (!isAnyMenuOpen()) {
player.setOption("sub-margin-y", "22") //player.setOption("sub-margin-y", "22")
controlsBar.visible = false controlsBar.visible = false
controlsBackground.visible = false controlsBackground.visible = false
titleBar.visible = false titleBar.visible = false
@ -230,7 +235,7 @@ ApplicationWindow {
} }
function showControls() { function showControls() {
if (! controlsBar.visible) { if (!controlsBar.visible) {
updateControls() updateControls()
//player.setOption("sub-margin-y", String(controlsBar.height + progressBar.height)) //player.setOption("sub-margin-y", String(controlsBar.height + progressBar.height))
controlsBar.visible = true controlsBar.visible = true
@ -259,9 +264,9 @@ ApplicationWindow {
title: "URL / File Path" title: "URL / File Path"
standardButtons: StandardButton.Cancel | StandardButton.Open standardButtons: StandardButton.Cancel | StandardButton.Open
onAccepted: { onAccepted: {
player.command(["loadfile", pathText.text]) player.command(["loadfile", pathText.text])
pathText.text = "" pathText.text = ""
} }
TextField { TextField {
id: pathText id: pathText
placeholderText: qsTr("URL / File Path") placeholderText: qsTr("URL / File Path")
@ -337,343 +342,376 @@ ApplicationWindow {
property string cycleVideoAspect: "Shift+A" property string cycleVideoAspect: "Shift+A"
} }
MenuBar { MenuBar {
id: menuBar id: menuBar
//width: parent.width //width: parent.width
height: Screen.height / 24 height: Screen.height / 24
delegate: MenuBarItem { delegate: MenuBarItem {
id: menuBarItem id: menuBarItem
contentItem: Text { contentItem: Text {
text: menuBarItem.text text: menuBarItem.text
font.family: notoFont.name font.family: notoFont.name
font.pixelSize: 14 font.pixelSize: 14
renderType: Text.NativeRendering renderType: Text.NativeRendering
opacity: 1 opacity: 1
color: menuBarItem.highlighted ? "#5a50da" : "white" color: menuBarItem.highlighted ? "#5a50da" : "white"
horizontalAlignment: Text.AlignLeft horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 10
implicitHeight: 10
opacity: 1
color: menuBarItem.highlighted ? "#c0c0f0" : "transparent"
}
} }
background: Rectangle { background: Rectangle {
implicitWidth: 10 implicitWidth: parent.width
implicitHeight: 10 implicitHeight: 10
opacity: 1 color: "black"
color: menuBarItem.highlighted ? "#c0c0f0" : "transparent" opacity: 0.6
}
Menu {
id: fileMenuBarItem
title: "File"
width: 100
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 10
color: "black"
opacity: 0.6
}
delegate: CustomMenuItem {
}
Action {
text: "Open File"
onTriggered: fileDialog.open()
shortcut: keybinds.openFile
}
Action {
text: "Open URI/URL"
onTriggered: loadDialog.open()
shortcut: keybinds.openURI
}
Action {
text: "Exit"
onTriggered: Qt.quit()
shortcut: keybinds.quit
}
}
Menu {
id: playbackMenuBarItem
title: "Playback"
width: 100
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 10
color: "black"
opacity: 0.6
}
delegate: CustomMenuItem {
width: 100
}
Action {
text: "Play/Pause"
onTriggered: {
player.command(["cycle", "pause"])
updateControls()
}
shortcut: String(keybinds.playPause)
}
Action {
text: "Rewind 10s"
onTriggered: {
player.command(["seek", "-10"])
updateControls()
}
shortcut: keybinds.rewind10
}
Action {
text: "Forward 10s"
onTriggered: {
player.command(["seek", "10"])
updateControls()
}
shortcut: keybinds.forward10
}
Action {
text: "Rewind 5s"
onTriggered: {
player.command(["seek", "-5"])
updateControls()
}
shortcut: keybinds.rewind5
}
Action {
text: "Forward 5s"
onTriggered: {
player.command(["seek", "5"])
updateControls()
}
shortcut: keybinds.forward5
}
Action {
text: "Forward Frame"
onTriggered: {
player.command(["frame-step"])
updateControls()
}
shortcut: keybinds.forwardFrame
}
Action {
text: "Back Frame"
onTriggered: {
player.command(["frame-back-step"])
updateControls()
}
shortcut: keybinds.backwardFrame
}
Action {
text: "Switch Aspect Ratio"
onTriggered: {
player.command(
["cycle-values", "video-aspect", "16:9", "4:3", "2.35:1", "-1"])
}
shortcut: keybinds.cycleVideoAspect
}
}
Menu {
id: tracksMenuBarItem
title: "Tracks"
width: 150
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 10
color: "black"
opacity: 0.6
}
delegate: CustomMenuItem {
width: 100
}
Action {
text: "Track Menu"
onTriggered: {
tracksMenuUpdate()
subtitlesMenu.visible = !subtitlesMenu.visible
subtitlesMenuBackground.visible = !subtitlesMenuBackground.visible
}
shortcut: keybinds.tracks
}
Action {
text: "Cycle Subs"
onTriggered: {
player.command(["cycle", "sub"])
}
shortcut: keybinds.cycleSub
}
Action {
text: "Cycle Subs Backwards"
onTriggered: {
player.command(["cycle", "sub", "down"])
}
shortcut: keybinds.cycleSubBackwards
}
Action {
text: "Cycle Audio"
onTriggered: {
player.command(["cycle", "audio"])
}
shortcut: keybinds.cycleAudio
}
Action {
text: "Cycle Video"
onTriggered: {
player.command(["cycle", "video"])
}
shortcut: keybinds.cycleVideo
}
}
Menu {
id: viewMenuBarItem
title: "View"
width: 100
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 10
color: "black"
opacity: 0.6
}
delegate: CustomMenuItem {
}
Action {
text: "Fullscreen"
onTriggered: {
toggleFullscreen()
}
shortcut: keybinds.fullscreen
}
Action {
text: "Stats For Nerds"
onTriggered: {
player.command(
["script-binding", "stats/display-stats-toggle"])
}
shortcut: keybinds.statsForNerds
}
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "1"
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "2"
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "3"
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "4"
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "5"
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "6"
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "7"
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "8"
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "9"
}
Action {
onTriggered: player.skipToNinth(parseInt(shortcut))
shortcut: "0"
} }
} }
background: Rectangle { Rectangle {
implicitWidth: parent.width id: subtitlesMenuBackground
implicitHeight: 10 anchors.fill: subtitlesMenu
Layout.fillWidth: true
Layout.fillHeight: true
visible: false
color: "black" color: "black"
opacity: 0.6 opacity: 0.6
} }
Menu { Rectangle {
id: fileMenuBarItem id: subtitlesMenu
title: "File" color: "transparent"
width: 100 width: childrenRect.width
background: Rectangle { height: childrenRect.height
implicitWidth: parent.width visible: false
implicitHeight: 10 anchors.centerIn: player
color: "black" anchors.right: player.right
opacity: 0.6 anchors.bottom: progressBar.top
} border.color: "black"
delegate: CustomMenuItem {} border.width: 2
Text {
Action { id: audioLabel
text: "Open File" anchors.left: parent.left
onTriggered: fileDialog.open() anchors.right: parent.right
shortcut: keybinds.openFile text: "Audio"
color: "white"
font.family: notoFont.name
font.pixelSize: 14
renderType: Text.NativeRendering
horizontalAlignment: Text.AlignHCenter
opacity: 1
} }
Action { ComboBox {
text: "Open URI/URL" id: audioList
onTriggered: loadDialog.open() textRole: "key"
shortcut: keybinds.openURI anchors.top: audioLabel.bottom
model: ListModel {
id: audioModel
}
onActivated: {
player.command(["set", "aid", String(audioModel.get(
index).value)])
}
opacity: 1
} }
Action { Text {
text: "Exit" id: subLabel
onTriggered: Qt.quit() anchors.left: parent.left
shortcut: keybinds.quit anchors.right: parent.right
text: "Subtitles"
color: "white"
font.family: notoFont.name
font.pixelSize: 14
anchors.top: audioList.bottom
renderType: Text.NativeRendering
horizontalAlignment: Text.AlignHCenter
opacity: 1
}
ComboBox {
id: subList
textRole: "key"
anchors.top: subLabel.bottom
model: ListModel {
id: subModel
}
onActivated: {
player.command(["set", "sid", String(subModel.get(
index).value)])
}
opacity: 1
}
Text {
id: vidLabel
anchors.left: parent.left
anchors.right: parent.right
text: "Video"
color: "white"
font.family: notoFont.name
font.pixelSize: 14
anchors.top: subList.bottom
renderType: Text.NativeRendering
horizontalAlignment: Text.AlignHCenter
opacity: 1
}
ComboBox {
id: vidList
textRole: "key"
anchors.top: vidLabel.bottom
model: ListModel {
id: vidModel
}
onActivated: {
player.command(["set", "vid", String(vidModel.get(
index).value)])
}
opacity: 1
} }
} }
Menu {
id: playbackMenuBarItem
title: "Playback"
width: 100
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 10
color: "black"
opacity: 0.6
}
delegate: CustomMenuItem { width: 100 }
Action {
text: "Play/Pause"
onTriggered: {
player.command(["cycle", "pause"])
updateControls()
}
shortcut: String(keybinds.playPause)
}
Action {
text: "Rewind 10s"
onTriggered: {
player.command(["seek", "-10"])
updateControls()
}
shortcut: keybinds.rewind10
}
Action {
text: "Forward 10s"
onTriggered: {
player.command(["seek", "10"])
updateControls()
}
shortcut: keybinds.forward10
}
Action {
text: "Rewind 5s"
onTriggered: {
player.command(["seek", "-5"])
updateControls()
}
shortcut: keybinds.rewind5
}
Action {
text: "Forward 5s"
onTriggered: {
player.command(["seek", "5"])
updateControls()
}
shortcut: keybinds.forward5
}
Action {
text: "Forward Frame"
onTriggered: {
player.command(["frame-step"])
updateControls()
}
shortcut: keybinds.forwardFrame
}
Action {
text: "Back Frame"
onTriggered: {
player.command(["frame-back-step"])
updateControls()
}
shortcut: keybinds.backwardFrame
}
Action {
text: "Switch Aspect Ratio"
onTriggered: {
player.command(["cycle-values", "video-aspect", "16:9", "4:3", "2.35:1", "-1"])
}
shortcut: keybinds.cycleVideoAspect
}
}
Menu {
id: tracksMenuBarItem
title: "Tracks"
width: 150
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 10
color: "black"
opacity: 0.6
}
delegate: CustomMenuItem { width: 100 }
Action {
text: "Track Menu"
onTriggered: {
tracksMenuUpdate()
subtitlesMenu.visible = !subtitlesMenu.visible
subtitlesMenuBackground.visible = !subtitlesMenuBackground.visible
}
shortcut: keybinds.tracks
}
Action {
text: "Cycle Subs"
onTriggered: {
player.command(["cycle", "sub"])
}
shortcut: keybinds.cycleSub
}
Action {
text: "Cycle Subs Backwards"
onTriggered: {
player.command(["cycle", "sub", "down"])
}
shortcut: keybinds.cycleSubBackwards
}
Action {
text: "Cycle Audio"
onTriggered: {
player.command(["cycle", "audio"])
}
shortcut: keybinds.cycleAudio
}
Action {
text: "Cycle Video"
onTriggered: {
player.command(["cycle", "video"])
}
shortcut: keybinds.cycleVideo
}
}
Menu {
id: viewMenuBarItem
title: "View"
width: 100
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 10
color: "black"
opacity: 0.6
}
delegate: CustomMenuItem {}
Action {
text: "Fullscreen"
onTriggered: {
toggleFullscreen()
}
shortcut: keybinds.fullscreen
}
Action {
text: "Stats For Nerds"
onTriggered: {
player.command(["script-binding", "stats/display-stats-toggle"])
}
shortcut: keybinds.statsForNerds
}
}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "1";}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "2";}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "3";}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "4";}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "5";}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "6";}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "7";}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "8";}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "9";}
Action { onTriggered: player.skipToNinth(parseInt(shortcut)); shortcut: "0";}
}
Rectangle {
id: subtitlesMenuBackground
anchors.fill: subtitlesMenu
Layout.fillWidth: true
Layout.fillHeight: true
visible: false
color: "black"
opacity: 0.6
}
Rectangle {
id: subtitlesMenu
color: "transparent"
width: childrenRect.width
height: childrenRect.height
visible: false
anchors.centerIn: player
anchors.right: player.right
anchors.bottom: progressBar.top
border.color: "black"
border.width: 2
Text {
id: audioLabel
anchors.left: parent.left
anchors.right: parent.right
text: "Audio"
color: "white"
font.family: notoFont.name
font.pixelSize: 14
renderType: Text.NativeRendering
horizontalAlignment: Text.AlignHCenter
opacity: 1
}
ComboBox {
id: audioList
textRole: "key"
anchors.top: audioLabel.bottom
model: ListModel {
id: audioModel
}
onActivated: {
player.command(["set", "aid", String(
audioModel.get(index).value)])
}
opacity: 1
}
Text {
id: subLabel
anchors.left: parent.left
anchors.right: parent.right
text: "Subtitles"
color: "white"
font.family: notoFont.name
font.pixelSize: 14
anchors.top: audioList.bottom
renderType: Text.NativeRendering
horizontalAlignment: Text.AlignHCenter
opacity: 1
}
ComboBox {
id: subList
textRole: "key"
anchors.top: subLabel.bottom
model: ListModel {
id: subModel
}
onActivated: {
player.command(["set", "sid", String(
subModel.get(index).value)])
}
opacity: 1
}
Text {
id: vidLabel
anchors.left: parent.left
anchors.right: parent.right
text: "Video"
color: "white"
font.family: notoFont.name
font.pixelSize: 14
anchors.top: subList.bottom
renderType: Text.NativeRendering
horizontalAlignment: Text.AlignHCenter
opacity: 1
}
ComboBox {
id: vidList
textRole: "key"
anchors.top: vidLabel.bottom
model: ListModel {
id: vidModel
}
onActivated: {
player.command(["set", "vid", String(
vidModel.get(index).value)])
}
opacity: 1
}
}
Rectangle { Rectangle {
id: titleBackground id: titleBackground
height: titleBar.height height: titleBar.height
@ -721,7 +759,7 @@ ApplicationWindow {
Rectangle { Rectangle {
id: controlsBackground id: controlsBackground
height: controlsBar.visible ? controlsBar.height + (progressBar.topPadding * 2) height: controlsBar.visible ? controlsBar.height + (progressBar.topPadding * 2)
- (progressBackground.height * 2) : 0 - (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
@ -731,37 +769,37 @@ ApplicationWindow {
opacity: 0.6 opacity: 0.6
} }
Rectangle { Rectangle {
id: nativeSubtitles id: nativeSubtitles
height: nativeSubs.font.pixelSize + 4 height: nativeSubs.font.pixelSize + 4
visible: nativeSubs.text == "" ? false : true visible: nativeSubs.text == "" ? false : true
anchors.left: controlsBar.left anchors.left: controlsBar.left
anchors.right: controlsBar.right anchors.right: controlsBar.right
anchors.bottom: controlsBackground.top anchors.bottom: controlsBackground.top
radius: 5 radius: 5
color: "transparent" color: "transparent"
Label { Label {
id: nativeSubs id: nativeSubs
width: parent.width width: parent.width
text: "" text: ""
color: "white" color: "white"
font.family: notoFont.name font.family: notoFont.name
font.pixelSize: 24 font.pixelSize: 24
renderType: Text.NativeRendering renderType: Text.NativeRendering
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
anchors.bottom: parent.top anchors.bottom: parent.top
opacity: 1 opacity: 1
wrapMode: Text.WrapAtWordBoundaryOrAnywhere wrapMode: Text.WrapAtWordBoundaryOrAnywhere
background: Rectangle { background: Rectangle {
color: Qt.rgba(0, 0, 0, 0.6) color: Qt.rgba(0, 0, 0, 0.6)
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
}
} }
} }
}
Rectangle { Rectangle {
id: controlsBar id: controlsBar
@ -945,7 +983,7 @@ ApplicationWindow {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
onMoved: { onMoved: {
player.command(["set", "volume", Math.round( player.command(["set", "volume", Math.round(
volumeBar.value).toString()]) volumeBar.value).toString()])
updateVolume() updateVolume()
} }
@ -1047,6 +1085,5 @@ ApplicationWindow {
} }
} }
} }
} }
} }