Warning, /multimedia/kasts/src/qml/PlaybackRateCustomizerDialog.qml is written in an unsupported language. File is not indexed.

0001 /**
0002  * SPDX-FileCopyrightText: 2023 Bart De Vries <bart@mogwai.be>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 import QtQuick
0008 import QtQuick.Controls as Controls
0009 import QtQuick.Layouts
0010 
0011 import org.kde.kirigami as Kirigami
0012 import org.kde.kasts
0013 import org.kde.kasts.settings
0014 
0015 Kirigami.Dialog {
0016     id: customizeRatesDialog
0017     title: i18nc("@title:window", "Playback Rate Presets")
0018     padding: Kirigami.Units.largeSpacing
0019     preferredWidth: Kirigami.Units.gridUnit * 16 + Kirigami.Units.smallSpacing
0020 
0021     closePolicy: Controls.Popup.CloseOnEscape
0022     standardButtons: Kirigami.Dialog.Save | Kirigami.Dialog.Cancel
0023 
0024     ListModel {
0025         id: rateModel
0026 
0027         Component.onCompleted: {
0028             for (var rate in SettingsManager.playbackRates) {
0029                 rateModel.append({"value": SettingsManager.playbackRates[rate] / 100.0,
0030                                   "name": (SettingsManager.playbackRates[rate] / 100.0).toFixed(2) + "x"});
0031             }
0032         }
0033     }
0034 
0035     function getRateList() {
0036         var list = [];
0037         for (var i = 0; i < rateModel.count; i++) {
0038             list.push(Math.round(rateModel.get(i).value * 100));
0039         }
0040         return list;
0041     }
0042 
0043     ColumnLayout {
0044         id: playbackRateList
0045 
0046         implicitWidth: customizeRatesDialog.width
0047         spacing: Kirigami.Units.largeSpacing
0048 
0049         RowLayout {
0050             Layout.fillWidth: true
0051             Controls.Label {
0052                 Layout.fillWidth: true
0053                 text: i18nc("@info Label for controls to add new playback rate preset", "New Preset:")
0054             }
0055 
0056             Kirigami.Chip {
0057                 text: (Math.round(rateSlider.value * 20) / 20.0).toFixed(2)
0058                 closable: false
0059                 checkable: false
0060             }
0061 
0062             Controls.Button {
0063                 id: addButton
0064                 icon.name: "list-add"
0065                 text: i18nc("@action:button Add new playback rate value to list", "Add")
0066                 Controls.ToolTip.visible: hovered
0067                 Controls.ToolTip.delay: Kirigami.Units.toolTipDelay
0068                 Controls.ToolTip.text: i18nc("@info:tooltip", "Add new playback rate value to list")
0069                 onClicked: {
0070                     var found = false;
0071                     var insertIndex = 0;
0072                     var newValue = (Math.round(rateSlider.value * 20) / 20.0);
0073                     for (var i = 0; i < rateModel.count; i++) {
0074                         if (newValue == rateModel.get(i).value) {
0075                             found = true;
0076                             break;
0077                         }
0078                         if (newValue > rateModel.get(i).value) {
0079                             insertIndex = i + 1;
0080                         }
0081                     }
0082                     if (!found) {
0083                         rateModel.insert(insertIndex, {"value": newValue,
0084                                                        "name": newValue.toFixed(2) + "x"});
0085                     }
0086                 }
0087             }
0088         }
0089 
0090         RowLayout {
0091             Layout.fillWidth: true
0092             Layout.bottomMargin: Kirigami.Units.gridUnit
0093 
0094             Controls.Button {
0095                 text: "-"
0096                 implicitWidth: addButton.height
0097                 implicitHeight: addButton.height
0098                 onClicked: rateSlider.value = Math.max(0.0, rateSlider.value - 0.05)
0099                 Controls.ToolTip.visible: hovered
0100                 Controls.ToolTip.delay: Kirigami.Units.toolTipDelay
0101                 Controls.ToolTip.text: i18nc("@action:button", "Decrease playback rate")
0102             }
0103 
0104             Controls.Slider {
0105                 id: rateSlider
0106                 Layout.fillWidth: true
0107                 from: 0
0108                 to: 3
0109                 value: 1
0110                 handle.implicitWidth: implicitHeight // workaround to make slider handle position itself exactly at the location of the click
0111             }
0112 
0113             Controls.Button {
0114                 text: "+"
0115                 implicitWidth: addButton.height
0116                 implicitHeight: addButton.height
0117                 onClicked: rateSlider.value = Math.min(3.0, rateSlider.value + 0.05)
0118                 Controls.ToolTip.visible: hovered
0119                 Controls.ToolTip.delay: Kirigami.Units.toolTipDelay
0120                 Controls.ToolTip.text: i18nc("@action:button", "Increase playback rate")
0121             }
0122         }
0123 
0124         Controls.Label {
0125             text: i18nc("@title:group List of custom playback rates", "Current Presets:")
0126         }
0127 
0128         GridLayout {
0129             columns: 4
0130             Layout.fillWidth: true
0131             Repeater {
0132                 model: rateModel
0133                 delegate: Kirigami.Chip {
0134                     Layout.fillWidth: true
0135                     text: model.value.toFixed(2)
0136                     closable: true
0137                     onRemoved: {
0138                         for (var i = 0; i < rateModel.count; i++) {
0139                             if (model.value == rateModel.get(i).value) {
0140                                 rateModel.remove(i);
0141                                 break;
0142                             }
0143                         }
0144                     }
0145                 }
0146             }
0147         }
0148     }
0149 }