diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp
index 784424a..dff369a 100644
--- a/src/MpvPlayerBackend.cpp
+++ b/src/MpvPlayerBackend.cpp
@@ -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
{
diff --git a/src/MpvPlayerBackend.h b/src/MpvPlayerBackend.h
index 8032383..700b58a 100644
--- a/src/MpvPlayerBackend.h
+++ b/src/MpvPlayerBackend.h
@@ -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);
diff --git a/src/qml/CustomComboBox.qml b/src/qml/CustomComboBox.qml
index 8d7d225..5ef68de 100644
--- a/src/qml/CustomComboBox.qml
+++ b/src/qml/CustomComboBox.qml
@@ -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"
}
}
}
diff --git a/src/qml/TrackItem.qml b/src/qml/TrackItem.qml
new file mode 100644
index 0000000..9d7fe0a
--- /dev/null
+++ b/src/qml/TrackItem.qml
@@ -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)
+ }
+}
diff --git a/src/qml/main.qml b/src/qml/main.qml
index 110a256..fea84e2 100644
--- a/src/qml/main.qml
+++ b/src/qml/main.qml
@@ -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
}
}
}
diff --git a/src/qml/qml.qrc b/src/qml/qml.qrc
index 3fb65a2..307e646 100644
--- a/src/qml/qml.qrc
+++ b/src/qml/qml.qrc
@@ -4,6 +4,7 @@
CustomComboBox.qml
CustomMenuItem.qml
CustomMenu.qml
+ TrackItem.qml
Translator.qml
translations.js
icons/play.svg
diff --git a/src/qml/translations.js b/src/qml/translations.js
index 0e96a45..e549dbc 100644
--- a/src/qml/translations.js
+++ b/src/qml/translations.js
@@ -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",
diff --git a/src/utils.cpp b/src/utils.cpp
index aaa41bf..b2d92e0 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -23,6 +23,10 @@ getPlatformName()
void
SetDPMS(bool on)
{
+ qDebug() << getPlatformName();
+ if (getPlatformName() != "xcb") {
+ return;
+ }
Display* dpy = QX11Info::display();
if (on) {
DPMSEnable(dpy);