diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index b3234b8..0fb8fd8 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -322,6 +322,37 @@ MpvPlayerBackend::toggleOnTop() AlwaysOnTop(window()->winId(), onTop); } +void +MpvPlayerBackend::addSpeed(const QVariant& speed) +{ + QString speedString = + QString::number(getProperty("speed").toDouble() + speed.toDouble()); + speedString = speedString.left(speedString.lastIndexOf('.') + 2); + setSpeed(QVariant(speedString)); +} + +void +MpvPlayerBackend::subtractSpeed(const QVariant& speed) +{ + QString speedString = + QString::number(getProperty("speed").toDouble() - speed.toDouble()); + speedString = speedString.left(speedString.lastIndexOf('.') + 2); + setSpeed(QVariant(speedString)); +} + +void +MpvPlayerBackend::changeSpeed(const QVariant& speedFactor) +{ + setSpeed(QVariant(getProperty("speed").toDouble() * speedFactor.toDouble())); +} + +void +MpvPlayerBackend::setSpeed(const QVariant& speed) +{ + command(QVariantList() << "set" + << "speed" << speed.toString()); +} + void MpvPlayerBackend::on_mpv_events() { diff --git a/src/MpvPlayerBackend.h b/src/MpvPlayerBackend.h index 6a0a1db..4236b49 100644 --- a/src/MpvPlayerBackend.h +++ b/src/MpvPlayerBackend.h @@ -42,7 +42,10 @@ public slots: void updatePrev(const QVariant& val); void updateVolume(const QVariant& val); void updatePlayPause(const QVariant& val); - + void addSpeed(const QVariant& speed); + void subtractSpeed(const QVariant& speed); + void changeSpeed(const QVariant& speedFactor); + void setSpeed(const QVariant& speed); QVariant getTrack(const QString& track); void setTrack(const QVariant& track, const QVariant& id); void setVolume(const QVariant& volume); diff --git a/src/qml/main.qml b/src/qml/main.qml index 35f4c31..717c386 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -327,8 +327,8 @@ ApplicationWindow { property string screenshotWithoutSubtitles: "Shift+S" property string fullScreenshot: "Ctrl+S" property string nyanCat: "Ctrl+N" - property string decreaseSpeedBy10Percent: "[" - property string increaseSpeedBy10Percent: "]" + property string decreaseSpeedByPointOne: "[" + property string increaseSpeedByPointOne: "]" property string halveSpeed: "{" property string doubleSpeed: "}" property string increaseVolume: "*" @@ -484,25 +484,25 @@ ApplicationWindow { shortcut: keybinds.forward5 } Action { - text: translate.getTranslation("SPEED_DECREASE_10PERCENT", + text: translate.getTranslation("SPEED_DECREASE_POINT_ONE", i18n.language) onTriggered: { - player.command(["multiply", "speed", "1/1.1"]) + player.subtractSpeed(0.1) } - shortcut: keybinds.decreaseSpeedBy10Percent + shortcut: keybinds.decreaseSpeedByPointOne } Action { - text: translate.getTranslation("SPEED_INCREASE_10PERCENT", + text: translate.getTranslation("SPEED_INCREASE_POINT_ONE", i18n.language) onTriggered: { - player.command(["multiply", "speed", "1.1"]) + player.addSpeed(0.1) } - shortcut: keybinds.increaseSpeedBy10Percent + shortcut: keybinds.increaseSpeedByPointOne } Action { text: translate.getTranslation("HALVE_SPEED", i18n.language) onTriggered: { - player.command(["multiply", "speed", "0.5"]) + player.changeSpeed(0.5) } shortcut: keybinds.halveSpeed } @@ -510,7 +510,7 @@ ApplicationWindow { text: translate.getTranslation("DOUBLE_SPEED", i18n.language) onTriggered: { - player.command(["multiply", "speed", "2.0"]) + player.changeSpeed(2) } shortcut: keybinds.doubleSpeed } diff --git a/src/qml/translations.js b/src/qml/translations.js index 1babfc2..cedffbf 100644 --- a/src/qml/translations.js +++ b/src/qml/translations.js @@ -15,8 +15,8 @@ var translations = { FORWARD_10S: "Forward 10s", REWIND_5S: "Rewind 5s", FORWARD_5S: "Forward 5s", - SPEED_DECREASE_10PERCENT: "Speed -10%", - SPEED_INCREASE_10PERCENT: "Speed +10%", + SPEED_DECREASE_POINT_ONE: "Speed -0.1", + SPEED_INCREASE_POINT_ONE: "Speed +0.1", HALVE_SPEED: "Halve Speed", DOUBLE_SPEED: "Double Speed", BACKWARD_FRAME: "Back a frame", @@ -58,8 +58,8 @@ var translations = { FORWARD_10S: "Adelantar 10s", REWIND_5S: "Retrasar 5s", FORWARD_5S: "Adelantar 5s", - SPEED_DECREASE_10PERCENT: "Velocidad -10%", - SPEED_INCREASE_10PERCENT: "Velocidad +10%", + SPEED_DECREASE_POINT_ONE: "Velocidad -0.1", + SPEED_INCREASE_POINT_ONE: "Velocidad +0.1", HALVE_SPEED: "Dividir velocidad a la mitad", DOUBLE_SPEED: "Duplicar velocidad", BACKWARD_FRAME: "Retrasar un frame", @@ -83,7 +83,7 @@ var translations = { ABOUT_QT: "Sobre Qt", TITLE: "Título", TOGGLE_ALWAYS_ON_TOP: "Fijar ventana", - DISABLE_TRACK: "Eliminar pista" + DISABLE_TRACK: "Eliminar pista" }, german: { SAVE_SCREENSHOT: "Bildschirmfoto speichern nach", @@ -101,8 +101,8 @@ var translations = { FORWARD_10S: "Vorspulen 10s", REWIND_5S: "Rückspulen 5s", FORWARD_5S: "Vorspulen 5s", - SPEED_DECREASE_10PERCENT: "Geschwindigkeit -10%", - SPEED_INCREASE_10PERCENT: "Geschwindigkeit +10%", + SPEED_DECREASE_POINT_ONE: "Geschwindigkeit -0.1", + SPEED_INCREASE_POINT_ONE: "Geschwindigkeit +0.1", HALVE_SPEED: "Halbe Geschwindigkeit", DOUBLE_SPEED: "Doppelte Geschwindigkeit", BACKWARD_FRAME: "Ein Bild zurück", @@ -126,7 +126,7 @@ var translations = { ABOUT_QT: "Über QT", TITLE: "Titel", TOGGLE_ALWAYS_ON_TOP: "Immer im Vordergrund", - DISABLE_TRACK: "Spur deaktivieren" + DISABLE_TRACK: "Spur deaktivieren" }, french: { SAVE_SCREENSHOT: "Enregistrer la capture d'écran dans", @@ -144,8 +144,8 @@ var translations = { FORWARD_10S: "Avancer de 10s", REWIND_5S: "Reculer de 5s", FORWARD_5S: "Avancer de 5s", - SPEED_DECREASE_10PERCENT: "Vitesse -10%", - SPEED_INCREASE_10PERCENT: "Vitesse +10%", + SPEED_DECREASE_POINT_ONE: "Vitesse -0.1", + SPEED_INCREASE_POINT_ONE: "Vitesse +0.1", HALVE_SPEED: "Réduire de moitié la vitesse", DOUBLE_SPEED: "Doubler la vitesse", BACKWARD_FRAME: "Reculer d'une image", @@ -169,7 +169,7 @@ var translations = { ABOUT_QT: "A propos de Qt", TITLE: "Titre", TOGGLE_ALWAYS_ON_TOP: "Toujours au-dessu", - DISABLE_TRACK: "Désactiver la piste" + DISABLE_TRACK: "Désactiver la piste" }, italian: { SAVE_SCREENSHOT: "Salva schermata", @@ -187,8 +187,8 @@ var translations = { FORWARD_10S: "Avanti 10s", REWIND_5S: "Indietro 5s", FORWARD_5S: "Avanti 5s", - SPEED_DECREASE_10PERCENT: "Velocità -10%", - SPEED_INCREASE_10PERCENT: "Velocità +10%", + SPEED_DECREASE_POINT_ONE: "Velocità -0.1", + SPEED_INCREASE_POINT_ONE: "Velocità +0.1", HALVE_SPEED: "Dimezza velocità", DOUBLE_SPEED: "Raddoppia velocità", BACKWARD_FRAME: "Indietro di un fotogramma", @@ -212,7 +212,7 @@ var translations = { ABOUT_QT: "Info su Qt", TITLE: "Titolo", TOGGLE_ALWAYS_ON_TOP: "Mantieni in primo piano", - DISABLE_TRACK: "Disabilita traccia" + DISABLE_TRACK: "Disabilita traccia" }, russian: { SAVE_SCREENSHOT: "Сохранить снимок экрана...", @@ -230,8 +230,8 @@ var translations = { FORWARD_10S: "Перемотать вперед на 10 секунд", REWIND_5S: "Перемотать назад на 5 секунд", FORWARD_5S: "Перемотать вперед на 5 секунд", - SPEED_DECREASE_10PERCENT: "Уменьшить скорость на 10%", - SPEED_INCREASE_10PERCENT: "Увеличить скорость на 10%", + SPEED_DECREASE_POINT_ONE: "Уменьшить скорость на 0.1", + SPEED_INCREASE_POINT_ONE: "Увеличить скорость на 0.1", HALVE_SPEED: "Замедлить воспроизведение в 2 раза", DOUBLE_SPEED: "Ускорить воспроизведение в 2 раза", BACKWARD_FRAME: "Вернуться к предыдущему кадру", @@ -271,8 +271,8 @@ var translations = { FORWARD_10S: "Spol Frem 10s", REWIND_5S: "Spol Tilbake 5s", FORWARD_5S: "Spol Frem 5s", - SPEED_DECREASE_10PERCENT: "Hastighet -10%", - SPEED_INCREASE_10PERCENT: "Hastighet +10%", + SPEED_DECREASE_POINT_ONE: "Hastighet -0.1", + SPEED_INCREASE_POINT_ONE: "Hastighet +0.1", HALVE_SPEED: "Halv Hastighet", DOUBLE_SPEED: "Dobbel Hastighet", BACKWARD_FRAME: "Gå Tilbake Én Ramme",