Warning, /multimedia/kid3/src/qml/app/FrameDelegate.qml is written in an unsupported language. File is not indexed.
0001 /**
0002 * \file FrameDelegate.qml
0003 * Delegate for frame table.
0004 *
0005 * \b Project: Kid3
0006 * \author Urs Fleisch
0007 * \date 16 Feb 2015
0008 *
0009 * Copyright (C) 2015-2018 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.Controls 2.4
0026 import Kid3 1.1 as Kid3
0027
0028 ItemDelegate {
0029 id: frameDelegate
0030
0031 property int tagNr
0032 property QtObject frameModel: app.tag(tagNr).frameModel
0033 property QtObject genreModel: app.tag(tagNr).genreModel
0034
0035 highlighted: ListView.view.currentIndex === index
0036 onClicked: ListView.view.currentIndex = index
0037
0038 Component {
0039 id: textEdit
0040 Item {
0041 TextField {
0042 anchors.left: parent.left
0043 anchors.right: parent.right
0044 anchors.verticalCenter: parent.verticalCenter
0045 text: value
0046 selectByMouse: true
0047 focus: true
0048 onAccepted: {
0049 focus = false
0050 }
0051 onActiveFocusChanged: {
0052 if (!activeFocus) {
0053 script.setRoleData(frameModel, index, "value", text)
0054 }
0055 }
0056 Component.onDestruction: {
0057 // When another frame is edited, neither activeFocusChanged() nor
0058 // editingFinished() is signaled and the changes are lost.
0059 // Use this workaround to call onActiveFocusChanged() in this case.
0060 if (activeFocus) {
0061 focus = false
0062 }
0063 }
0064 }
0065 }
0066 }
0067
0068 Component {
0069 id: differentTextEdit
0070 Item {
0071 ComboBox {
0072 anchors.left: parent.left
0073 anchors.right: parent.right
0074 anchors.verticalCenter: parent.verticalCenter
0075 editable: true
0076 model: [String.fromCharCode(0x2260)].concat(
0077 script.getRoleData(frameModel, index, "completions"))
0078 onCurrentTextChanged: script.setRoleData(frameModel, index, "value",
0079 currentIndex === -1 && editText || currentText)
0080 Component.onCompleted: {
0081 currentIndex = model.indexOf(value)
0082 if (currentIndex === -1) {
0083 editText = value;
0084 }
0085 }
0086 }
0087 }
0088 }
0089
0090 Component {
0091 id: genreEdit
0092 Item {
0093 ComboBox {
0094 anchors.left: parent.left
0095 anchors.right: parent.right
0096 anchors.verticalCenter: parent.verticalCenter
0097 editable: tagNr !== Kid3.Frame.Tag_1
0098 textRole: "display"
0099 model: genreModel
0100 onCurrentTextChanged: script.setRoleData(frameModel, index, "value",
0101 editable && currentIndex === -1 && editText || currentText)
0102 Component.onCompleted: {
0103 currentIndex = genreModel.getRowForGenre(value)
0104 if (currentIndex === -1 && editable) {
0105 editText = value;
0106 }
0107 }
0108 Component.onDestruction: {
0109 // When another frame is edited, currentTextChanged() is not signaled
0110 // and the changes are lost.
0111 if (editable && editText && editText !== currentText) {
0112 script.setRoleData(frameModel, index, "value", editText)
0113 }
0114 }
0115 }
0116 }
0117 }
0118
0119 Component {
0120 id: valueText
0121 Item {
0122 Label {
0123 anchors.leftMargin: constants.margins
0124 anchors.fill: parent
0125 text: value
0126 verticalAlignment: Text.AlignVCenter
0127 clip: true
0128 }
0129 MouseArea {
0130 anchors.fill: parent
0131 onClicked: {
0132 frameDelegate.ListView.view.currentIndex = index
0133 }
0134 }
0135 }
0136 }
0137
0138 Rectangle {
0139 anchors.fill: parent
0140 color: highlighted ? constants.highlightColor : "transparent"
0141
0142 CheckBox {
0143 id: frameEnabledCheckBox
0144 anchors.left: parent.left
0145 anchors.verticalCenter: parent.verticalCenter
0146 onClicked: {
0147 // QTBUG-7932, assigning is not possible
0148 script.setRoleData(frameModel, index, "checkState",
0149 checked ? Qt.Checked : Qt.Unchecked)
0150 }
0151 // workaround for QTBUG-31627
0152 // should work with "checked: checkState === Qt.Checked" with Qt >= 5.3
0153 Binding {
0154 target: frameEnabledCheckBox
0155 property: "checked"
0156 value: checkState === Qt.Checked
0157 }
0158 }
0159 Rectangle {
0160 id: frameModifiedImage
0161 anchors.left: frameEnabledCheckBox.right
0162 anchors.verticalCenter: parent.verticalCenter
0163 color: truncated ? constants.errorColor : "transparent"
0164 width: constants.gu(2)
0165 height: constants.gu(2)
0166 Text {
0167 font.family: materialFont.name
0168 font.pixelSize: 16
0169 text: "M"
0170 color: frameNameLabel.color
0171 visible: modified
0172 }
0173 MouseArea {
0174 id: mouseArea
0175 anchors.fill: parent
0176 }
0177 ToolTip {
0178 parent: frameNameLabel
0179 visible: mouseArea.pressed && truncated && notice
0180 text: notice
0181 }
0182 }
0183 Label {
0184 id: frameNameLabel
0185 anchors.left: frameModifiedImage.right
0186 anchors.verticalCenter: parent.verticalCenter
0187 width: Math.min(constants.gu(11),
0188 (parent.width - constants.gu(4) - 2 * constants.margins) / 2)
0189 text: name
0190 clip: true
0191 color: highlighted
0192 ? constants.highlightedTextColor : constants.textColor
0193 }
0194
0195 Loader {
0196 anchors.left: frameNameLabel.right
0197 anchors.right: parent.right
0198 anchors.rightMargin: constants.margins
0199 height: parent.height
0200 sourceComponent: !frameDelegate.ListView.isCurrentItem
0201 ? valueText : frameType === Kid3.Frame.FT_Genre
0202 ? genreEdit : value === String.fromCharCode(0x2260)
0203 ? differentTextEdit : textEdit
0204 }
0205
0206 }
0207 }