Debian Codegraph @

src/qml/Haruna/Components/SubtitleTracksMenu.qml

raw
1 /*
2 * SPDX-FileCopyrightText: 2023 George Florea Bănuș <[email protected]>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7 pragma ComponentBehavior: Bound
8
9 import QtQuick
10 import QtQuick.Controls
11
12 import org.kde.haruna
13
14 Menu {
15 id: root
16
17 required property MpvVideo m_mpv
18 required property bool isPrimarySubtitleMenu
19
20 property TracksModel model: m_mpv.subtitleTracksModel
21
22 enabled: model.rowCount > 1
23
24 contentItem: ListView {
25 property bool hasCheckables: false
26 property bool hasIcons: false
27
28 model: root.model
29 implicitWidth: contentItem.children.reduce((maxWidth, child) => Math.max(maxWidth, child.implicitWidth), 0)
30 implicitHeight: Math.max(1, contentItem.childrenRect.height)
31 spacing: 0
32 clip: true
33 delegate: MenuItem {
34 id: delegate
35
36 required property int trackId
37 required property string displayText
38 required property string language
39 required property string title
40 required property string codec
41
42 enabled: root.isPrimarySubtitleMenu
43 ? delegate.trackId !== root.m_mpv.secondarySubtitleId || delegate.trackId === 0
44 : delegate.trackId !== root.m_mpv.subtitleId || delegate.trackId === 0
45 checkable: true
46 checked: root.isPrimarySubtitleMenu
47 ? delegate.trackId === root.m_mpv.subtitleId
48 : delegate.trackId === root.m_mpv.secondarySubtitleId
49 text: delegate.displayText
50 onTriggered: {
51 if (root.isPrimarySubtitleMenu) {
52 root.m_mpv.subtitleId = delegate.trackId
53 } else {
54 root.m_mpv.secondarySubtitleId = delegate.trackId
55 }
56 }
57 }
58 }
59 }