1
0
Fork 0

[UI+Backend] Made tracks menu better.

This commit is contained in:
Kitteh 2018-11-07 17:22:18 +00:00
parent a73a6f7c1a
commit 0bd62e70aa
8 changed files with 125 additions and 94 deletions

View file

@ -67,7 +67,6 @@ public:
{ MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params },
{ MPV_RENDER_PARAM_INVALID, nullptr }
};
if (mpv_render_context_create(&obj->mpv_gl, obj->mpv, params) < 0)
throw std::runtime_error("failed to initialize mpv GL context");
mpv_render_context_set_update_callback(obj->mpv_gl, on_mpv_redraw, obj);
@ -282,6 +281,18 @@ MpvPlayerBackend::getTracks() const
return mpv::qt::get_property_variant(mpv, "track-list");
}
void
MpvPlayerBackend::setTrack(const QVariant& track, const QVariant& id)
{
command(QVariantList() << "set" << track << id);
}
QVariant
MpvPlayerBackend::getTrack(const QString& track)
{
return mpv::qt::get_property_variant(mpv, track);
}
QVariant
MpvPlayerBackend::createTimestamp(const QVariant& seconds) const
{

View file

@ -39,6 +39,8 @@ public slots:
void toggleOnTop();
QVariant getTracks() const;
QVariant getTrack(const QString& track);
void setTrack(const QVariant& track, const QVariant& id);
void setVolume(const QVariant& volume);
void addVolume(const QVariant& volume);
void loadFile(const QVariant& filename);

View file

@ -1,13 +1,16 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import Qt.labs.settings 1.0
ComboBox {
id: control
width: parent.width
height: 10
FontLoader {
id: notoFont
source: "fonts/NotoSans.ttf"
Settings {
id: appearance
category: "Appearance"
property string fontName: "Roboto"
}
indicator: Canvas {
@ -38,8 +41,8 @@ ComboBox {
leftPadding: 2
rightPadding: control.indicator.width + control.spacing
text: control.displayText
font.family: notoFont.name
color: "white"
font.family: appearance.fontName
color: control.pressed ? "#5a50da" : "white"
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
@ -48,8 +51,7 @@ ComboBox {
implicitWidth: 120
implicitHeight: 40
color: "transparent"
border.color: "black"
border.width: 2
opacity: 0.6
}
popup: Popup {
@ -74,9 +76,7 @@ ComboBox {
background: Rectangle {
opacity: 0.6
color: "white"
border.color: "black"
border.width: 2
color: "orange"
}
}
}

16
src/qml/TrackItem.qml Normal file
View file

@ -0,0 +1,16 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import Qt.labs.settings 1.0
Action {
id: trackItem
property string trackType: "none"
property string trackID: "none"
checkable: true
checked: false
onTriggered: {
checked = player.getTrack(trackType)
player.setTrack(trackType, trackID)
}
}

View file

@ -104,9 +104,24 @@ ApplicationWindow {
}
function tracksUpdate() {
subModel.clear()
audioModel.clear()
vidModel.clear()
for (var i = 0, len = audioMenu.count; i < len; i++) {
var audioAction = audioMenu.actionAt(i)
if (audioAction.trackID != "no") {
audioMenu.removeAction(audioAction)
}
}
for (var i = 0, len = videoMenu.count; i < len; i++) {
var videoAction = audioMenu.actionAt(i)
if (videoAction.trackID != "no") {
videoMenu.removeAction(videoAction)
}
}
for (var i = 0, len = subMenu.count; i < len; i++) {
var subAction = subMenu.actionAt(i)
if (subAction.trackID != "no") {
subMenu.removeAction(subAction)
}
}
var newTracks = player.getTracks()
for (var i = 0, len = newTracks.length; i < len; i++) {
@ -117,30 +132,38 @@ ApplicationWindow {
String(track["lang"]))
var trackTitle = track["title"]
if (trackType == "sub") {
subModel.append({
key: trackLang,
value: trackID
})
if (track["selected"]) {
subList.currentIndex = subList.count - 1
}
var component = Qt.createComponent("TrackItem.qml")
var action = component.createObject(subMenu, {
text: trackLang,
trackID: String(
trackID),
trackType: "sid",
checked: track["selected"]
})
action.ActionGroup.group = subMenuGroup
subMenu.addAction(action)
} else if (trackType == "audio") {
audioModel.append({
key: (trackTitle === undefined ? "" : trackTitle + " ")
+ trackLang,
value: trackID
})
if (track["selected"]) {
audioList.currentIndex = audioList.count - 1
}
var component = Qt.createComponent("TrackItem.qml")
var action = component.createObject(audioMenu, {
text: (trackTitle == "undefined" ? "" : trackTitle + " ") + (trackLang == "undefined" ? "" : trackLang),
trackID: String(
trackID),
trackType: "aid",
checked: track["selected"]
})
action.ActionGroup.group = audioMenuGroup
audioMenu.addAction(action)
} else if (trackType == "video") {
vidModel.append({
key: "Video " + trackID,
value: trackID
})
if (track["selected"]) {
vidList.currentIndex = vidList.count - 1
}
var component = Qt.createComponent("TrackItem.qml")
var action = component.createObject(videoMenu, {
text: "Video " + trackID,
trackID: String(
trackID),
trackType: "vid",
checked: track["selected"]
})
action.ActionGroup.group = videoMenuGroup
videoMenu.addAction(action)
}
}
}
@ -606,25 +629,16 @@ ApplicationWindow {
CustomMenu {
title: translate.getTranslation("AUDIO", i18n.language)
Rectangle {
color: "white"
opacity: 1
width: parent.width
height: 40
ComboBox {
anchors.fill: parent
id: audioList
textRole: "key"
model: ListModel {
id: audioModel
}
onActivated: {
player.command(["set", "aid", String(
subModel.get(index).value)])
}
opacity: 1
}
id: audioMenu
ActionGroup {
id: audioMenuGroup
}
TrackItem {
text: translate.getTranslation("DISABLE_TRACK",
i18n.language)
trackType: "aid"
trackID: "no"
ActionGroup.group: audioMenuGroup
}
}
}
@ -644,25 +658,16 @@ ApplicationWindow {
CustomMenu {
title: translate.getTranslation("VIDEO", i18n.language)
Rectangle {
color: "white"
opacity: 1
width: parent.width
height: 40
ComboBox {
anchors.fill: parent
id: vidList
textRole: "key"
model: ListModel {
id: vidModel
}
onActivated: {
player.command(["set", "vid", String(
subModel.get(index).value)])
}
opacity: 1
}
id: videoMenu
ActionGroup {
id: videoMenuGroup
}
TrackItem {
text: translate.getTranslation("DISABLE_TRACK",
i18n.language)
trackType: "vid"
trackID: "no"
ActionGroup.group: videoMenuGroup
}
}
}
@ -690,25 +695,16 @@ ApplicationWindow {
CustomMenu {
title: translate.getTranslation("SUBTITLES", i18n.language)
Rectangle {
color: "white"
opacity: 1
width: parent.width
height: 40
ComboBox {
anchors.fill: parent
id: subList
textRole: "key"
model: ListModel {
id: subModel
}
onActivated: {
player.command(["set", "sid", String(
subModel.get(index).value)])
}
opacity: 1
}
id: subMenu
ActionGroup {
id: subMenuGroup
}
TrackItem {
text: translate.getTranslation("DISABLE_TRACK",
i18n.language)
trackType: "sid"
trackID: "no"
ActionGroup.group: subMenuGroup
}
}
}

View file

@ -4,6 +4,7 @@
<file>CustomComboBox.qml</file>
<file>CustomMenuItem.qml</file>
<file>CustomMenu.qml</file>
<file>TrackItem.qml</file>
<file>Translator.qml</file>
<file>translations.js</file>
<file>icons/play.svg</file>

View file

@ -39,7 +39,8 @@ var translations = {
ABOUT: "About",
ABOUT_QT: "About Qt",
TITLE: "Title",
TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top"
TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top",
DISABLE_TRACK: "Disable Track"
},
spanish: {
SAVE_SCREENSHOT: "Guardar captura en",

View file

@ -23,6 +23,10 @@ getPlatformName()
void
SetDPMS(bool on)
{
qDebug() << getPlatformName();
if (getPlatformName() != "xcb") {
return;
}
Display* dpy = QX11Info::display();
if (on) {
DPMSEnable(dpy);