1
0
Fork 0

[Backend] Moved speed controls to backend.

This commit is contained in:
Kitteh 2018-11-08 17:36:41 +00:00
parent 63eff586b0
commit c492c57f82
4 changed files with 63 additions and 29 deletions

View file

@ -322,6 +322,37 @@ MpvPlayerBackend::toggleOnTop()
AlwaysOnTop(window()->winId(), onTop); 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 void
MpvPlayerBackend::on_mpv_events() MpvPlayerBackend::on_mpv_events()
{ {

View file

@ -42,7 +42,10 @@ public slots:
void updatePrev(const QVariant& val); void updatePrev(const QVariant& val);
void updateVolume(const QVariant& val); void updateVolume(const QVariant& val);
void updatePlayPause(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); QVariant getTrack(const QString& track);
void setTrack(const QVariant& track, const QVariant& id); void setTrack(const QVariant& track, const QVariant& id);
void setVolume(const QVariant& volume); void setVolume(const QVariant& volume);

View file

@ -327,8 +327,8 @@ ApplicationWindow {
property string screenshotWithoutSubtitles: "Shift+S" property string screenshotWithoutSubtitles: "Shift+S"
property string fullScreenshot: "Ctrl+S" property string fullScreenshot: "Ctrl+S"
property string nyanCat: "Ctrl+N" property string nyanCat: "Ctrl+N"
property string decreaseSpeedBy10Percent: "[" property string decreaseSpeedByPointOne: "["
property string increaseSpeedBy10Percent: "]" property string increaseSpeedByPointOne: "]"
property string halveSpeed: "{" property string halveSpeed: "{"
property string doubleSpeed: "}" property string doubleSpeed: "}"
property string increaseVolume: "*" property string increaseVolume: "*"
@ -484,25 +484,25 @@ ApplicationWindow {
shortcut: keybinds.forward5 shortcut: keybinds.forward5
} }
Action { Action {
text: translate.getTranslation("SPEED_DECREASE_10PERCENT", text: translate.getTranslation("SPEED_DECREASE_POINT_ONE",
i18n.language) i18n.language)
onTriggered: { onTriggered: {
player.command(["multiply", "speed", "1/1.1"]) player.subtractSpeed(0.1)
} }
shortcut: keybinds.decreaseSpeedBy10Percent shortcut: keybinds.decreaseSpeedByPointOne
} }
Action { Action {
text: translate.getTranslation("SPEED_INCREASE_10PERCENT", text: translate.getTranslation("SPEED_INCREASE_POINT_ONE",
i18n.language) i18n.language)
onTriggered: { onTriggered: {
player.command(["multiply", "speed", "1.1"]) player.addSpeed(0.1)
} }
shortcut: keybinds.increaseSpeedBy10Percent shortcut: keybinds.increaseSpeedByPointOne
} }
Action { Action {
text: translate.getTranslation("HALVE_SPEED", i18n.language) text: translate.getTranslation("HALVE_SPEED", i18n.language)
onTriggered: { onTriggered: {
player.command(["multiply", "speed", "0.5"]) player.changeSpeed(0.5)
} }
shortcut: keybinds.halveSpeed shortcut: keybinds.halveSpeed
} }
@ -510,7 +510,7 @@ ApplicationWindow {
text: translate.getTranslation("DOUBLE_SPEED", text: translate.getTranslation("DOUBLE_SPEED",
i18n.language) i18n.language)
onTriggered: { onTriggered: {
player.command(["multiply", "speed", "2.0"]) player.changeSpeed(2)
} }
shortcut: keybinds.doubleSpeed shortcut: keybinds.doubleSpeed
} }

View file

@ -15,8 +15,8 @@ var translations = {
FORWARD_10S: "Forward 10s", FORWARD_10S: "Forward 10s",
REWIND_5S: "Rewind 5s", REWIND_5S: "Rewind 5s",
FORWARD_5S: "Forward 5s", FORWARD_5S: "Forward 5s",
SPEED_DECREASE_10PERCENT: "Speed -10%", SPEED_DECREASE_POINT_ONE: "Speed -0.1",
SPEED_INCREASE_10PERCENT: "Speed +10%", SPEED_INCREASE_POINT_ONE: "Speed +0.1",
HALVE_SPEED: "Halve Speed", HALVE_SPEED: "Halve Speed",
DOUBLE_SPEED: "Double Speed", DOUBLE_SPEED: "Double Speed",
BACKWARD_FRAME: "Back a frame", BACKWARD_FRAME: "Back a frame",
@ -58,8 +58,8 @@ var translations = {
FORWARD_10S: "Adelantar 10s", FORWARD_10S: "Adelantar 10s",
REWIND_5S: "Retrasar 5s", REWIND_5S: "Retrasar 5s",
FORWARD_5S: "Adelantar 5s", FORWARD_5S: "Adelantar 5s",
SPEED_DECREASE_10PERCENT: "Velocidad -10%", SPEED_DECREASE_POINT_ONE: "Velocidad -0.1",
SPEED_INCREASE_10PERCENT: "Velocidad +10%", SPEED_INCREASE_POINT_ONE: "Velocidad +0.1",
HALVE_SPEED: "Dividir velocidad a la mitad", HALVE_SPEED: "Dividir velocidad a la mitad",
DOUBLE_SPEED: "Duplicar velocidad", DOUBLE_SPEED: "Duplicar velocidad",
BACKWARD_FRAME: "Retrasar un frame", BACKWARD_FRAME: "Retrasar un frame",
@ -101,8 +101,8 @@ var translations = {
FORWARD_10S: "Vorspulen 10s", FORWARD_10S: "Vorspulen 10s",
REWIND_5S: "Rückspulen 5s", REWIND_5S: "Rückspulen 5s",
FORWARD_5S: "Vorspulen 5s", FORWARD_5S: "Vorspulen 5s",
SPEED_DECREASE_10PERCENT: "Geschwindigkeit -10%", SPEED_DECREASE_POINT_ONE: "Geschwindigkeit -0.1",
SPEED_INCREASE_10PERCENT: "Geschwindigkeit +10%", SPEED_INCREASE_POINT_ONE: "Geschwindigkeit +0.1",
HALVE_SPEED: "Halbe Geschwindigkeit", HALVE_SPEED: "Halbe Geschwindigkeit",
DOUBLE_SPEED: "Doppelte Geschwindigkeit", DOUBLE_SPEED: "Doppelte Geschwindigkeit",
BACKWARD_FRAME: "Ein Bild zurück", BACKWARD_FRAME: "Ein Bild zurück",
@ -144,8 +144,8 @@ var translations = {
FORWARD_10S: "Avancer de 10s", FORWARD_10S: "Avancer de 10s",
REWIND_5S: "Reculer de 5s", REWIND_5S: "Reculer de 5s",
FORWARD_5S: "Avancer de 5s", FORWARD_5S: "Avancer de 5s",
SPEED_DECREASE_10PERCENT: "Vitesse -10%", SPEED_DECREASE_POINT_ONE: "Vitesse -0.1",
SPEED_INCREASE_10PERCENT: "Vitesse +10%", SPEED_INCREASE_POINT_ONE: "Vitesse +0.1",
HALVE_SPEED: "Réduire de moitié la vitesse", HALVE_SPEED: "Réduire de moitié la vitesse",
DOUBLE_SPEED: "Doubler la vitesse", DOUBLE_SPEED: "Doubler la vitesse",
BACKWARD_FRAME: "Reculer d'une image", BACKWARD_FRAME: "Reculer d'une image",
@ -187,8 +187,8 @@ var translations = {
FORWARD_10S: "Avanti 10s", FORWARD_10S: "Avanti 10s",
REWIND_5S: "Indietro 5s", REWIND_5S: "Indietro 5s",
FORWARD_5S: "Avanti 5s", FORWARD_5S: "Avanti 5s",
SPEED_DECREASE_10PERCENT: "Velocità -10%", SPEED_DECREASE_POINT_ONE: "Velocità -0.1",
SPEED_INCREASE_10PERCENT: "Velocità +10%", SPEED_INCREASE_POINT_ONE: "Velocità +0.1",
HALVE_SPEED: "Dimezza velocità", HALVE_SPEED: "Dimezza velocità",
DOUBLE_SPEED: "Raddoppia velocità", DOUBLE_SPEED: "Raddoppia velocità",
BACKWARD_FRAME: "Indietro di un fotogramma", BACKWARD_FRAME: "Indietro di un fotogramma",
@ -230,8 +230,8 @@ var translations = {
FORWARD_10S: "Перемотать вперед на 10 секунд", FORWARD_10S: "Перемотать вперед на 10 секунд",
REWIND_5S: "Перемотать назад на 5 секунд", REWIND_5S: "Перемотать назад на 5 секунд",
FORWARD_5S: "Перемотать вперед на 5 секунд", FORWARD_5S: "Перемотать вперед на 5 секунд",
SPEED_DECREASE_10PERCENT: "Уменьшить скорость на 10%", SPEED_DECREASE_POINT_ONE: "Уменьшить скорость на 0.1",
SPEED_INCREASE_10PERCENT: "Увеличить скорость на 10%", SPEED_INCREASE_POINT_ONE: "Увеличить скорость на 0.1",
HALVE_SPEED: "Замедлить воспроизведение в 2 раза", HALVE_SPEED: "Замедлить воспроизведение в 2 раза",
DOUBLE_SPEED: "Ускорить воспроизведение в 2 раза", DOUBLE_SPEED: "Ускорить воспроизведение в 2 раза",
BACKWARD_FRAME: "Вернуться к предыдущему кадру", BACKWARD_FRAME: "Вернуться к предыдущему кадру",
@ -271,8 +271,8 @@ var translations = {
FORWARD_10S: "Spol Frem 10s", FORWARD_10S: "Spol Frem 10s",
REWIND_5S: "Spol Tilbake 5s", REWIND_5S: "Spol Tilbake 5s",
FORWARD_5S: "Spol Frem 5s", FORWARD_5S: "Spol Frem 5s",
SPEED_DECREASE_10PERCENT: "Hastighet -10%", SPEED_DECREASE_POINT_ONE: "Hastighet -0.1",
SPEED_INCREASE_10PERCENT: "Hastighet +10%", SPEED_INCREASE_POINT_ONE: "Hastighet +0.1",
HALVE_SPEED: "Halv Hastighet", HALVE_SPEED: "Halv Hastighet",
DOUBLE_SPEED: "Dobbel Hastighet", DOUBLE_SPEED: "Dobbel Hastighet",
BACKWARD_FRAME: "Gå Tilbake Én Ramme", BACKWARD_FRAME: "Gå Tilbake Én Ramme",