[UI+Backend] Made tracks menu better.
This commit is contained in:
parent
a73a6f7c1a
commit
0bd62e70aa
|
@ -67,7 +67,6 @@ public:
|
||||||
{ MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params },
|
{ MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params },
|
||||||
{ MPV_RENDER_PARAM_INVALID, nullptr }
|
{ MPV_RENDER_PARAM_INVALID, nullptr }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mpv_render_context_create(&obj->mpv_gl, obj->mpv, params) < 0)
|
if (mpv_render_context_create(&obj->mpv_gl, obj->mpv, params) < 0)
|
||||||
throw std::runtime_error("failed to initialize mpv GL context");
|
throw std::runtime_error("failed to initialize mpv GL context");
|
||||||
mpv_render_context_set_update_callback(obj->mpv_gl, on_mpv_redraw, obj);
|
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");
|
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
|
QVariant
|
||||||
MpvPlayerBackend::createTimestamp(const QVariant& seconds) const
|
MpvPlayerBackend::createTimestamp(const QVariant& seconds) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,6 +39,8 @@ public slots:
|
||||||
void toggleOnTop();
|
void toggleOnTop();
|
||||||
QVariant getTracks() const;
|
QVariant getTracks() const;
|
||||||
|
|
||||||
|
QVariant getTrack(const QString& track);
|
||||||
|
void setTrack(const QVariant& track, const QVariant& id);
|
||||||
void setVolume(const QVariant& volume);
|
void setVolume(const QVariant& volume);
|
||||||
void addVolume(const QVariant& volume);
|
void addVolume(const QVariant& volume);
|
||||||
void loadFile(const QVariant& filename);
|
void loadFile(const QVariant& filename);
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
import QtQuick 2.11
|
import QtQuick 2.11
|
||||||
import QtQuick.Controls 2.4
|
import QtQuick.Controls 2.4
|
||||||
|
import Qt.labs.settings 1.0
|
||||||
|
|
||||||
ComboBox {
|
ComboBox {
|
||||||
id: control
|
id: control
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
height: 10
|
||||||
|
|
||||||
FontLoader {
|
Settings {
|
||||||
id: notoFont
|
id: appearance
|
||||||
source: "fonts/NotoSans.ttf"
|
category: "Appearance"
|
||||||
|
property string fontName: "Roboto"
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator: Canvas {
|
indicator: Canvas {
|
||||||
|
@ -38,8 +41,8 @@ ComboBox {
|
||||||
leftPadding: 2
|
leftPadding: 2
|
||||||
rightPadding: control.indicator.width + control.spacing
|
rightPadding: control.indicator.width + control.spacing
|
||||||
text: control.displayText
|
text: control.displayText
|
||||||
font.family: notoFont.name
|
font.family: appearance.fontName
|
||||||
color: "white"
|
color: control.pressed ? "#5a50da" : "white"
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
|
@ -48,8 +51,7 @@ ComboBox {
|
||||||
implicitWidth: 120
|
implicitWidth: 120
|
||||||
implicitHeight: 40
|
implicitHeight: 40
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
border.color: "black"
|
opacity: 0.6
|
||||||
border.width: 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
popup: Popup {
|
popup: Popup {
|
||||||
|
@ -74,9 +76,7 @@ ComboBox {
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
opacity: 0.6
|
opacity: 0.6
|
||||||
color: "white"
|
color: "orange"
|
||||||
border.color: "black"
|
|
||||||
border.width: 2
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/qml/TrackItem.qml
Normal file
16
src/qml/TrackItem.qml
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
148
src/qml/main.qml
148
src/qml/main.qml
|
@ -104,9 +104,24 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
function tracksUpdate() {
|
function tracksUpdate() {
|
||||||
subModel.clear()
|
for (var i = 0, len = audioMenu.count; i < len; i++) {
|
||||||
audioModel.clear()
|
var audioAction = audioMenu.actionAt(i)
|
||||||
vidModel.clear()
|
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()
|
var newTracks = player.getTracks()
|
||||||
|
|
||||||
for (var i = 0, len = newTracks.length; i < len; i++) {
|
for (var i = 0, len = newTracks.length; i < len; i++) {
|
||||||
|
@ -117,30 +132,38 @@ ApplicationWindow {
|
||||||
String(track["lang"]))
|
String(track["lang"]))
|
||||||
var trackTitle = track["title"]
|
var trackTitle = track["title"]
|
||||||
if (trackType == "sub") {
|
if (trackType == "sub") {
|
||||||
subModel.append({
|
var component = Qt.createComponent("TrackItem.qml")
|
||||||
key: trackLang,
|
var action = component.createObject(subMenu, {
|
||||||
value: trackID
|
text: trackLang,
|
||||||
|
trackID: String(
|
||||||
|
trackID),
|
||||||
|
trackType: "sid",
|
||||||
|
checked: track["selected"]
|
||||||
})
|
})
|
||||||
if (track["selected"]) {
|
action.ActionGroup.group = subMenuGroup
|
||||||
subList.currentIndex = subList.count - 1
|
subMenu.addAction(action)
|
||||||
}
|
|
||||||
} else if (trackType == "audio") {
|
} else if (trackType == "audio") {
|
||||||
audioModel.append({
|
var component = Qt.createComponent("TrackItem.qml")
|
||||||
key: (trackTitle === undefined ? "" : trackTitle + " ")
|
var action = component.createObject(audioMenu, {
|
||||||
+ trackLang,
|
text: (trackTitle == "undefined" ? "" : trackTitle + " ") + (trackLang == "undefined" ? "" : trackLang),
|
||||||
value: trackID
|
trackID: String(
|
||||||
|
trackID),
|
||||||
|
trackType: "aid",
|
||||||
|
checked: track["selected"]
|
||||||
})
|
})
|
||||||
if (track["selected"]) {
|
action.ActionGroup.group = audioMenuGroup
|
||||||
audioList.currentIndex = audioList.count - 1
|
audioMenu.addAction(action)
|
||||||
}
|
|
||||||
} else if (trackType == "video") {
|
} else if (trackType == "video") {
|
||||||
vidModel.append({
|
var component = Qt.createComponent("TrackItem.qml")
|
||||||
key: "Video " + trackID,
|
var action = component.createObject(videoMenu, {
|
||||||
value: trackID
|
text: "Video " + trackID,
|
||||||
|
trackID: String(
|
||||||
|
trackID),
|
||||||
|
trackType: "vid",
|
||||||
|
checked: track["selected"]
|
||||||
})
|
})
|
||||||
if (track["selected"]) {
|
action.ActionGroup.group = videoMenuGroup
|
||||||
vidList.currentIndex = vidList.count - 1
|
videoMenu.addAction(action)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -606,25 +629,16 @@ ApplicationWindow {
|
||||||
|
|
||||||
CustomMenu {
|
CustomMenu {
|
||||||
title: translate.getTranslation("AUDIO", i18n.language)
|
title: translate.getTranslation("AUDIO", i18n.language)
|
||||||
Rectangle {
|
id: audioMenu
|
||||||
color: "white"
|
ActionGroup {
|
||||||
opacity: 1
|
id: audioMenuGroup
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
TrackItem {
|
||||||
|
text: translate.getTranslation("DISABLE_TRACK",
|
||||||
|
i18n.language)
|
||||||
|
trackType: "aid"
|
||||||
|
trackID: "no"
|
||||||
|
ActionGroup.group: audioMenuGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -644,25 +658,16 @@ ApplicationWindow {
|
||||||
|
|
||||||
CustomMenu {
|
CustomMenu {
|
||||||
title: translate.getTranslation("VIDEO", i18n.language)
|
title: translate.getTranslation("VIDEO", i18n.language)
|
||||||
Rectangle {
|
id: videoMenu
|
||||||
color: "white"
|
ActionGroup {
|
||||||
opacity: 1
|
id: videoMenuGroup
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
TrackItem {
|
||||||
|
text: translate.getTranslation("DISABLE_TRACK",
|
||||||
|
i18n.language)
|
||||||
|
trackType: "vid"
|
||||||
|
trackID: "no"
|
||||||
|
ActionGroup.group: videoMenuGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -690,25 +695,16 @@ ApplicationWindow {
|
||||||
|
|
||||||
CustomMenu {
|
CustomMenu {
|
||||||
title: translate.getTranslation("SUBTITLES", i18n.language)
|
title: translate.getTranslation("SUBTITLES", i18n.language)
|
||||||
Rectangle {
|
id: subMenu
|
||||||
color: "white"
|
ActionGroup {
|
||||||
opacity: 1
|
id: subMenuGroup
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
TrackItem {
|
||||||
|
text: translate.getTranslation("DISABLE_TRACK",
|
||||||
|
i18n.language)
|
||||||
|
trackType: "sid"
|
||||||
|
trackID: "no"
|
||||||
|
ActionGroup.group: subMenuGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<file>CustomComboBox.qml</file>
|
<file>CustomComboBox.qml</file>
|
||||||
<file>CustomMenuItem.qml</file>
|
<file>CustomMenuItem.qml</file>
|
||||||
<file>CustomMenu.qml</file>
|
<file>CustomMenu.qml</file>
|
||||||
|
<file>TrackItem.qml</file>
|
||||||
<file>Translator.qml</file>
|
<file>Translator.qml</file>
|
||||||
<file>translations.js</file>
|
<file>translations.js</file>
|
||||||
<file>icons/play.svg</file>
|
<file>icons/play.svg</file>
|
||||||
|
|
|
@ -39,7 +39,8 @@ var translations = {
|
||||||
ABOUT: "About",
|
ABOUT: "About",
|
||||||
ABOUT_QT: "About Qt",
|
ABOUT_QT: "About Qt",
|
||||||
TITLE: "Title",
|
TITLE: "Title",
|
||||||
TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top"
|
TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top",
|
||||||
|
DISABLE_TRACK: "Disable Track"
|
||||||
},
|
},
|
||||||
spanish: {
|
spanish: {
|
||||||
SAVE_SCREENSHOT: "Guardar captura en",
|
SAVE_SCREENSHOT: "Guardar captura en",
|
||||||
|
|
|
@ -23,6 +23,10 @@ getPlatformName()
|
||||||
void
|
void
|
||||||
SetDPMS(bool on)
|
SetDPMS(bool on)
|
||||||
{
|
{
|
||||||
|
qDebug() << getPlatformName();
|
||||||
|
if (getPlatformName() != "xcb") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Display* dpy = QX11Info::display();
|
Display* dpy = QX11Info::display();
|
||||||
if (on) {
|
if (on) {
|
||||||
DPMSEnable(dpy);
|
DPMSEnable(dpy);
|
||||||
|
|
Loading…
Reference in a new issue