Warning, /multimedia/kid3/src/qml/app/AbstractSettingsPage.qml is written in an unsupported language. File is not indexed.
0001 /**
0002 * \file AbstractSettingsPage.qml
0003 * Base component for settings page.
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.Layouts 1.11
0026 import QtQuick.Controls 2.4
0027
0028 Page {
0029 id: page
0030
0031 signal clicked(int index)
0032 property list<SettingsElement> model
0033
0034 function activateAll() {
0035 for (var i = 0; i < model.length; i++) {
0036 if (model[i].onActivated) {
0037 model[i].onActivated()
0038 }
0039 }
0040 }
0041
0042 function deactivateAll() {
0043 for (var i = 0; i < model.length; i++) {
0044 if (model[i].onDeactivated) {
0045 model[i].onDeactivated()
0046 }
0047 }
0048 }
0049
0050 header: ToolBar {
0051 IconButton {
0052 id: prevButton
0053 anchors.left: parent.left
0054 anchors.verticalCenter: parent.verticalCenter
0055 iconName: "go-previous"
0056 color: titleLabel.color
0057 width: visible ? height : 0
0058 visible: page.StackView.view && page.StackView.view.depth > 1
0059 onClicked: page.StackView.view.pop()
0060 }
0061 Label {
0062 id: titleLabel
0063 anchors.left: prevButton.right
0064 anchors.right: parent.right
0065 anchors.verticalCenter: parent.verticalCenter
0066 clip: true
0067 text: page.title
0068 }
0069 }
0070
0071 Item {
0072 anchors.fill: parent
0073
0074 Component {
0075 id: booleanDelegate
0076 SettingsItem {
0077 text: _modelData.name
0078 control: CheckBox {
0079 checked: _modelData.value
0080 onClicked: _modelData.value = checked
0081 }
0082 }
0083 }
0084 Component {
0085 id: booleanEditDelegate
0086 SettingsItem {
0087 id: settingsItem
0088 text: _modelData.name
0089 control: RowLayout {
0090 IconButton {
0091 iconName: "edit"
0092 color: settingsItem.labelColor
0093 onClicked: _modelData.onEdit()
0094 }
0095 CheckBox {
0096 checked: _modelData.value
0097 onClicked: _modelData.value = checked
0098 }
0099 }
0100 }
0101 }
0102 Component {
0103 id: stringDelegate
0104 SettingsItem {
0105 text: _modelData.name
0106 control: TextField {
0107 width: Math.min(_modelData.width || constants.gu(40), page.width - 2 * constants.margins)
0108 text: _modelData.value
0109 selectByMouse: true
0110 onAccepted: {
0111 focus = false
0112 }
0113 onActiveFocusChanged: {
0114 if (!activeFocus) {
0115 _modelData.value = text
0116 }
0117 }
0118 }
0119 }
0120 }
0121 Component {
0122 id: numberDelegate
0123 SettingsItem {
0124 text: _modelData.name
0125 control: TextField {
0126 width: Math.min(_modelData.width || constants.gu(40), page.width - 2 * constants.margins)
0127 text: _modelData.value
0128 selectByMouse: true
0129 onAccepted: {
0130 focus = false
0131 }
0132 onActiveFocusChanged: {
0133 if (!activeFocus) {
0134 var nr = parseInt(text)
0135 if (!isNaN(nr)) {
0136 _modelData.value = nr
0137 }
0138 }
0139 }
0140 }
0141 }
0142 }
0143 Component {
0144 id: selectionDelegate
0145 SettingsItem {
0146 text: _modelData.name
0147 control: ComboBox {
0148 width: Math.min(_modelData.width || constants.gu(40), page.width - 2 * constants.margins)
0149 currentIndex: _modelData.value
0150 model: _modelData.dropDownModel
0151 onCurrentIndexChanged: _modelData.value = currentIndex
0152 }
0153 }
0154 }
0155 Component {
0156 id: selectionEditDelegate
0157 SettingsItem {
0158 id: settingsItem
0159 text: _modelData.name
0160 control: RowLayout {
0161 width: Math.min(_modelData.width || constants.gu(40), page.width - 2 * constants.margins)
0162 IconButton {
0163 iconName: "edit"
0164 color: settingsItem.labelColor
0165 onClicked: _modelData.onEdit()
0166 }
0167 ComboBox {
0168 Layout.fillWidth: true
0169 currentIndex: _modelData.value
0170 model: _modelData.dropDownModel
0171 onCurrentIndexChanged: _modelData.value = currentIndex
0172 }
0173 }
0174 }
0175 }
0176 Component {
0177 id: clickDelegate
0178 Standard {
0179 text: _modelData.name
0180 progression: true
0181 onClicked: {
0182 if (_modelData.onEdit) {
0183 _modelData.onEdit()
0184 } else {
0185 page.clicked(_index)
0186 }
0187 }
0188 ThinDivider {
0189 id: divider
0190 anchors {
0191 left: parent.left
0192 right: parent.right
0193 bottom: parent.bottom
0194 }
0195 }
0196 }
0197 }
0198
0199 ListView {
0200 id: listView
0201
0202 clip: true
0203 anchors.fill: parent
0204 model: page.model
0205 delegate: Loader {
0206 width: ListView.view.width
0207 property int _index: index
0208 property variant _modelData: modelData
0209 sourceComponent:
0210 if (modelData.dropDownModel)
0211 if (onEdit)
0212 selectionEditDelegate
0213 else
0214 selectionDelegate
0215 else if (typeof modelData.value === "boolean")
0216 if (onEdit)
0217 booleanEditDelegate
0218 else
0219 booleanDelegate
0220 else if (typeof modelData.value === "string")
0221 stringDelegate
0222 else if (typeof modelData.value === "number")
0223 numberDelegate
0224 else
0225 clickDelegate
0226 }
0227 }
0228 }
0229 }