Warning, /multimedia/kid3/src/qml/app/StringListEditPage.qml is written in an unsupported language. File is not indexed.
0001 /** 0002 * \file StringListEditPage.qml 0003 * Page to edit a list of strings. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 21 Feb 2019 0008 * 0009 * Copyright (C) 2019 Urs Fleisch 0010 * 0011 * This program is free software; you can redistribute it and/or modify 0012 * it under the terms of the GNU Lesser General Public License as published by 0013 * the Free Software Foundation; version 3. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Lesser General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Lesser General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 */ 0023 0024 import QtQuick 2.11 0025 import QtQuick.Layouts 1.11 0026 import QtQuick.Controls 2.4 0027 0028 Page { 0029 id: page 0030 0031 property alias model: listView.model 0032 property alias currentIndex: listView.currentIndex 0033 property alias count: listView.count 0034 property Dialog editDialog: textEditDialog 0035 0036 property var onAddClicked: function() { 0037 function modifyIfCompleted(ok) { 0038 editDialog.completed.disconnect(modifyIfCompleted) 0039 if (ok) { 0040 addElement(editDialog.getElement()) 0041 } 0042 } 0043 0044 editDialog.setElement({name: ""}) 0045 editDialog.completed.connect(modifyIfCompleted) 0046 editDialog.open() 0047 } 0048 0049 property var onEditClicked: function() { 0050 var idx = listView.currentIndex 0051 if (idx >= 0) { 0052 function modifyIfCompleted(ok) { 0053 editDialog.completed.disconnect(modifyIfCompleted) 0054 if (ok) { 0055 listView.model.set(idx, editDialog.getElement()) 0056 } 0057 } 0058 0059 editDialog.setElement(listView.model.get(idx)) 0060 editDialog.completed.connect(modifyIfCompleted) 0061 editDialog.open() 0062 } 0063 } 0064 0065 function addElement(element) { 0066 model.append(element) 0067 currentIndex = count - 1 0068 } 0069 0070 function setElements(lst) { 0071 listView.model.clear() 0072 for (var i = 0; i < lst.length; i++) { 0073 listView.model.append({"name": lst[i]}) 0074 } 0075 } 0076 0077 function getElements() { 0078 var lst = [] 0079 for (var i = 0; i < listView.model.count; i++) { 0080 lst.push(listView.model.get(i).name) 0081 } 0082 return lst 0083 } 0084 0085 title: qsTr("Edit") 0086 0087 Dialog { 0088 id: textEditDialog 0089 0090 signal completed(bool ok) 0091 0092 function setElement(element) { 0093 textLineEdit.text = element.name 0094 } 0095 0096 function getElement() { 0097 return {name: textLineEdit.text} 0098 } 0099 0100 modal: true 0101 width: Math.min(parent.width, constants.gu(70)) 0102 x: (parent.width - width) / 2 0103 y: 0 0104 standardButtons: Dialog.Ok | Dialog.Cancel 0105 0106 TextField { 0107 id: textLineEdit 0108 width: parent.width 0109 selectByMouse: true 0110 } 0111 0112 onAccepted: completed(true) 0113 onRejected: completed(false) 0114 } 0115 0116 header: ToolBar { 0117 IconButton { 0118 id: prevButton 0119 anchors.left: parent.left 0120 anchors.verticalCenter: parent.verticalCenter 0121 iconName: "go-previous" 0122 color: titleLabel.color 0123 width: visible ? height : 0 0124 visible: page.StackView.view && page.StackView.view.depth > 1 0125 onClicked: page.StackView.view.pop() 0126 } 0127 Label { 0128 id: titleLabel 0129 anchors.left: prevButton.right 0130 anchors.right: parent.right 0131 anchors.verticalCenter: parent.verticalCenter 0132 clip: true 0133 text: page.title 0134 } 0135 } 0136 0137 RowLayout { 0138 anchors { 0139 fill: parent 0140 margins: constants.margins 0141 } 0142 ListView { 0143 id: listView 0144 Layout.fillWidth: true 0145 Layout.fillHeight: true 0146 clip: true 0147 model: ListModel {} 0148 delegate: Standard { 0149 text: name 0150 highlighted: ListView.view.currentIndex === index 0151 onClicked: ListView.view.currentIndex = index 0152 background: Rectangle { 0153 color: highlighted ? constants.highlightColor : "transparent" 0154 } 0155 } 0156 } 0157 ColumnLayout { 0158 Layout.alignment: Qt.AlignTop 0159 Label { 0160 id: invisibleLabel 0161 visible: false 0162 } 0163 IconButton { 0164 iconName: "add" 0165 color: invisibleLabel.color 0166 onClicked: onAddClicked() 0167 } 0168 IconButton { 0169 iconName: "go-up" 0170 color: invisibleLabel.color 0171 onClicked: { 0172 var idx = listView.currentIndex 0173 if (idx > 0) { 0174 listView.model.move(idx, idx - 1, 1) 0175 listView.currentIndex = idx - 1 0176 } 0177 } 0178 } 0179 IconButton { 0180 iconName: "go-down" 0181 color: invisibleLabel.color 0182 onClicked: { 0183 var idx = listView.currentIndex 0184 if (idx >= 0 && idx < listView.model.count - 1) { 0185 listView.model.move(idx, idx + 1, 1) 0186 listView.currentIndex = idx + 1 0187 } 0188 } 0189 } 0190 IconButton { 0191 iconName: "edit" 0192 color: invisibleLabel.color 0193 onClicked: onEditClicked() 0194 } 0195 IconButton { 0196 iconName: "remove" 0197 color: invisibleLabel.color 0198 onClicked: { 0199 var idx = listView.currentIndex 0200 if (idx >= 0) { 0201 listView.model.remove(idx, 1) 0202 } 0203 } 0204 } 0205 } 0206 } 0207 }