Warning, /multimedia/haruna/src/qml/Haruna/Components/SubtitlesFolders.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2020 George Florea Bănuș <georgefb899@gmail.com>
0003 *
0004 * SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls
0010
0011 import org.kde.kirigami as Kirigami
0012
0013 // Subtitles Folders
0014 Item {
0015 id: root
0016
0017 // prevent creating multiple empty items
0018 // until the new one has been saved
0019 property bool canAddFolder: true
0020
0021 implicitHeight: sectionTitle.height + sfListView.implicitHeight + sfAddFolder.height + 25
0022
0023 Label {
0024 id: sectionTitle
0025
0026 text: i18nc("@title", "Load subtitles from")
0027 bottomPadding: 10
0028 }
0029
0030 ListView {
0031 id: sfListView
0032 property int sfDelegateHeight: 40
0033
0034 anchors.top: sectionTitle.bottom
0035 anchors.left: parent.left
0036 anchors.right: parent.right
0037 implicitHeight: count > 5
0038 ? 5 * sfListView.sfDelegateHeight + (sfListView.spacing * 4)
0039 : count * sfListView.sfDelegateHeight + (sfListView.spacing * (count - 1))
0040 spacing: 5
0041 clip: true
0042 model: subtitlesFoldersModel
0043 Layout.fillWidth: true
0044 ScrollBar.vertical: ScrollBar { id: scrollBar }
0045 delegate: Rectangle {
0046 id: sfDelegate
0047 width: root.width
0048 height: sfListView.sfDelegateHeight
0049 color: Kirigami.Theme.alternateBackgroundColor
0050
0051 Loader {
0052 id: sfLoader
0053 anchors.fill: parent
0054 sourceComponent: model.display === "" ? sfEditComponent : sfDisplayComponent
0055 }
0056
0057 Component {
0058 id: sfDisplayComponent
0059
0060 RowLayout {
0061
0062 Label {
0063 id: sfLabel
0064 text: model.display
0065 leftPadding: 10
0066 Layout.fillWidth: true
0067 }
0068
0069 Button {
0070 icon.name: "edit-entry"
0071 flat: true
0072 onClicked: {
0073 sfLoader.sourceComponent = sfEditComponent
0074 }
0075 }
0076
0077 Item { width: scrollBar.width }
0078 }
0079 } // Component: display
0080
0081 Component {
0082 id: sfEditComponent
0083
0084 RowLayout {
0085
0086 TextField {
0087 id: editField
0088 leftPadding: 10
0089 text: model.display
0090 Layout.leftMargin: 5
0091 Layout.fillWidth: true
0092 Component.onCompleted: editField.forceActiveFocus(Qt.MouseFocusReason)
0093 }
0094
0095 Button {
0096 property bool canDelete: editField.text === ""
0097 icon.name: "delete"
0098 flat: true
0099 onClicked: {
0100 if (!canDelete) {
0101 text = i18nc("@action:button", "Confirm deletion")
0102 canDelete = true
0103 return
0104 }
0105
0106 if (model.row === sfListView.count - 1) {
0107 root.canAddFolder = true
0108 }
0109 subtitlesFoldersModel.deleteFolder(model.row)
0110 const rows = sfListView.count
0111 sfListView.implicitHeight = rows > 5
0112 ? 5 * sfListView.sfDelegateHeight + (sfListView.spacing * 4)
0113 : rows * sfListView.sfDelegateHeight + (sfListView.spacing * (rows - 1))
0114
0115 }
0116 ToolTip {
0117 text: i18nc("@info:tooltip", "Delete this folder from list")
0118 }
0119 }
0120
0121 Button {
0122 icon.name: "dialog-ok"
0123 flat: true
0124 enabled: editField.text !== "" ? true : false
0125 onClicked: {
0126 subtitlesFoldersModel.updateFolder(editField.text, model.row)
0127 sfLoader.sourceComponent = sfDisplayComponent
0128 if (model.row === sfListView.count - 1) {
0129 root.canAddFolder = true
0130 }
0131 }
0132 ToolTip {
0133 text: i18nc("@info:tooltip", "Save changes")
0134 }
0135 }
0136
0137 Item { width: scrollBar.width }
0138 }
0139 } // Component: edit
0140 } // delegate: Rectangle
0141 }
0142
0143 Item {
0144 id: spacer
0145 anchors.top: sfListView.bottom
0146 height: 5
0147 }
0148
0149 Button {
0150 id: sfAddFolder
0151
0152 anchors.left: parent.left
0153 anchors.top: spacer.bottom
0154 icon.name: "list-add"
0155 text: i18nc("@action:button", "Add new folder")
0156 enabled: root.canAddFolder
0157 onClicked: {
0158 subtitlesFoldersModel.addFolder()
0159 const rows = sfListView.count
0160 sfListView.implicitHeight = rows > 5
0161 ? 5 * sfListView.sfDelegateHeight + (sfListView.spacing * 4)
0162 : rows * sfListView.sfDelegateHeight + (sfListView.spacing * (rows - 1))
0163 root.canAddFolder = false
0164 }
0165 }
0166 }