From 20e262b7093434ef5860d1db64fbae88b7c18a88 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Tue, 6 Nov 2018 07:32:49 +0000 Subject: [PATCH] [UI+Backend] Custom keybinds, made player init after renderer created. --- KittehPlayer.pro | 2 +- src/MpvPlayerBackend.cpp | 25 +++++++------- src/qml/main.qml | 75 +++++++++++++++++++++++++++++++++------- 3 files changed, 76 insertions(+), 26 deletions(-) diff --git a/KittehPlayer.pro b/KittehPlayer.pro index 5f8d9d5..fcd6c5e 100644 --- a/KittehPlayer.pro +++ b/KittehPlayer.pro @@ -1,7 +1,7 @@ TARGET = KittehPlayer TEMPLATE = app -QT += qml quickcontrols2 widgets core-private gui-private +QT += qml quickcontrols2 widgets SOURCES += src/main.cpp src/MpvPlayerBackend.cpp CONFIG += release diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index 18f8ec5..74b73c8 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -67,6 +67,7 @@ public: 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); + QMetaObject::invokeMethod(obj,"startPlayer"); } return QQuickFramebufferObject::Renderer::createFramebufferObject(size); @@ -176,6 +177,7 @@ QVariant MpvPlayerBackend::getProperty(const QString &name) const void MpvPlayerBackend::command(const QVariant& params) { + qDebug() << params; mpv::qt::command_variant(mpv, params); } @@ -197,56 +199,56 @@ void MpvPlayerBackend::launchAboutQt() void MpvPlayerBackend::togglePlayPause() { - mpv::qt::command_variant(mpv, QVariantList() << "cycle" << "pause"); + command(QVariantList() << "cycle" << "pause"); } void MpvPlayerBackend::toggleMute() { - mpv::qt::command_variant(mpv, QVariantList() << "cycle" << "mute"); + command(QVariantList() << "cycle" << "mute"); } void MpvPlayerBackend::nextAudioTrack() { - mpv::qt::command_variant(mpv, QVariantList() << "cycle" << "audio"); + command(QVariantList() << "cycle" << "audio"); } void MpvPlayerBackend::nextSubtitleTrack() { - mpv::qt::command_variant(mpv, QVariantList() << "cycle" << "sub"); + command(QVariantList() << "cycle" << "sub"); } void MpvPlayerBackend::nextVideoTrack() { - mpv::qt::command_variant(mpv, QVariantList() << "cycle" << "video"); + command(QVariantList() << "cycle" << "video"); } void MpvPlayerBackend::prevPlaylistItem() { - mpv::qt::command_variant(mpv, QVariantList() << "playlist-prev"); + command(QVariantList() << "playlist-prev"); } void MpvPlayerBackend::nextPlaylistItem() { - mpv::qt::command_variant(mpv, QVariantList() << "playlist-next" << "force"); + command(QVariantList() << "playlist-next" << "force"); } void MpvPlayerBackend::loadFile(const QVariant &filename) { - mpv::qt::command_variant(mpv, QVariantList() << "loadfile" << filename); + command(QVariantList() << "loadfile" << filename); } void MpvPlayerBackend::setVolume(const QVariant &volume) { - mpv::qt::command_variant(mpv, QVariantList() << "set" << "volume" << volume); + command(QVariantList() << "set" << "volume" << volume); } void MpvPlayerBackend::addVolume(const QVariant &volume) { - mpv::qt::command_variant(mpv, QVariantList() << "add" << "volume" << volume); + command(QVariantList() << "add" << "volume" << volume); } void MpvPlayerBackend::seek(const QVariant &seekTime) { - mpv::qt::command_variant(mpv, QVariantList() << "seek" << seekTime); + command(QVariantList() << "seek" << seekTime); } QVariant MpvPlayerBackend::getTracks() const @@ -331,6 +333,5 @@ QQuickFramebufferObject::Renderer *MpvPlayerBackend::createRenderer() const { window()->setPersistentOpenGLContext(true); window()->setPersistentSceneGraph(true); - return new MpvRenderer(const_cast(this)); } diff --git a/src/qml/main.qml b/src/qml/main.qml index 8e674a2..b4da7b7 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -97,19 +97,6 @@ ApplicationWindow { property bool nyanCat: false } - Timer { - id: initTimer - interval: 1000 - running: false - repeat: false - onTriggered: { - player.startPlayer() - } - } - Component.onCompleted: { - initTimer.start() - } - function startPlayer() { var args = Qt.application.arguments var len = Qt.application.arguments.length @@ -393,6 +380,27 @@ ApplicationWindow { property string increaseVolume: "*" property string decreaseVolume: "/" property string mute: "m" + property string customKeybind0:"" + property string customKeybind0Command: "" + property string customKeybind1:"" + property string customKeybind1Command: "" + property string customKeybind2:"" + property string customKeybind2Command: "" + property string customKeybind3:"" + property string customKeybind3Command: "" + property string customKeybind4:"" + property string customKeybind4Command: "" + property string customKeybind5:"" + property string customKeybind5Command: "" + property string customKeybind6:"" + property string customKeybind6Command: "" + property string customKeybind7:"" + property string customKeybind7Command: "" + property string customKeybind8:"" + property string customKeybind8Command: "" + property string customKeybind9:"" + property string customKeybind9Command: "" + } MenuBar { id: menuBar @@ -800,6 +808,47 @@ ApplicationWindow { onTriggered: player.skipToNinth(parseInt(shortcut)) shortcut: "0" } + + Action { + onTriggered: player.command(keybinds.customKeybind0Command) + shortcut: keybinds.customKeybind0 + } + Action { + onTriggered: player.command(keybinds.customKeybind1Command) + shortcut: keybinds.customKeybind1 + } + Action { + onTriggered: player.command(keybinds.customKeybind2Command) + shortcut: keybinds.customKeybind2 + } + Action { + onTriggered: player.command(keybinds.customKeybind3Command) + shortcut: keybinds.customKeybind3 + } + Action { + onTriggered: player.command(keybinds.customKeybind4Command) + shortcut: keybinds.customKeybind4 + } + Action { + onTriggered: player.command(keybinds.customKeybind5Command) + shortcut: keybinds.customKeybind5 + } + Action { + onTriggered: player.command(keybinds.customKeybind6Command) + shortcut: keybinds.customKeybind6 + } + Action { + onTriggered: player.command(keybinds.customKeybind7Command) + shortcut: keybinds.customKeybind7 + } + Action { + onTriggered: player.command(keybinds.customKeybind8Command) + shortcut: keybinds.customKeybind8 + } + Action { + onTriggered: player.command(keybinds.customKeybind9Command) + shortcut: keybinds.customKeybind9 + } } Rectangle {