Warning, /plasma/kdeplasma-addons/applets/timer/package/contents/ui/configTimes.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2020 Ćukasz Korbel <corebell.it@gmail.com>
0003 *
0004 * SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006
0007 import QtQuick
0008 import QtQuick.Controls 2.5 as QQC2
0009 import QtQuick.Layouts 1.0
0010 import org.kde.kirigami 2.20 as Kirigami
0011 import org.kde.plasma.plasmoid 2.0
0012 import org.kde.kcmutils as KCM
0013
0014 KCM.ScrollViewKCM {
0015 id: timesPage
0016 property var cfg_predefinedTimers: []
0017 readonly property int maxListSize: 15
0018
0019 signal configurationChanged()
0020
0021 Component.onCompleted: {
0022 for (var i of plasmoid.configuration.predefinedTimers) {
0023 timeListModel.append({"time": i})
0024 }
0025 }
0026
0027 ListModel {
0028 id: timeListModel
0029 function addTimer(value) {
0030 timeListModel.append({"time": value})
0031 cfg_predefinedTimers.splice(count, 0, value)
0032 timesPage.configurationChanged()
0033 }
0034 function removeTimer(index) {
0035 remove(index)
0036 cfg_predefinedTimers.splice(index, 1)
0037 timesPage.configurationChanged()
0038 }
0039 function moveTimer(oldIndex, newIndex) {
0040 move(oldIndex, newIndex, 1)
0041 cfg_predefinedTimers[oldIndex] = get(oldIndex).time
0042 cfg_predefinedTimers[newIndex] = get(newIndex).time
0043 timesPage.configurationChanged()
0044 }
0045 function setTimer(index, newValue) {
0046 setProperty(index, "time", newValue)
0047 cfg_predefinedTimers[index] = newValue
0048 timesPage.configurationChanged()
0049 }
0050 }
0051
0052 view: ListView {
0053 id: timeListView
0054 anchors.margins: 4
0055 model: timeListModel
0056 spacing: parent.spacing
0057 clip: true
0058 reuseItems: true
0059 delegate: timeEditDelegate
0060 add: Transition {
0061 NumberAnimation { properties: "y"; duration: Kirigami.Units.longDuration }
0062 }
0063 displaced: Transition {
0064 NumberAnimation { properties: "y"; duration: Kirigami.Units.longDuration }
0065 }
0066
0067 Kirigami.PlaceholderMessage {
0068 visible: timeListView.count === 0
0069 anchors.centerIn: parent
0070 width: parent.width - (Kirigami.Units.gridUnit * 4)
0071 text: i18n("If you add predefined timers here, they will appear in plasmoid context menu.");
0072 }
0073 }
0074
0075 footer: RowLayout {
0076 QQC2.Button {
0077 icon.name: "list-add"
0078 text: i18n("Add")
0079 enabled: timeListModel.count < maxListSize
0080 onClicked: {
0081 timeListModel.addTimer("0")
0082 timeListView.positionViewAtEnd()
0083 }
0084 }
0085 }
0086
0087 Component {
0088 id: timeEditDelegate
0089 Kirigami.SwipeListItem {
0090 id: timeEditItem
0091 width: timeListView.width
0092 contentItem: Row {
0093 spacing: Kirigami.Units.gridUnit
0094 Kirigami.ListItemDragHandle {
0095 anchors.verticalCenter: parent.verticalCenter
0096 enabled: !editor.editable
0097 listItem: timeEditItem
0098 listView: timeListView
0099 onMoveRequested: (oldIndex, newIndex) => {
0100 timeListModel.moveTimer(oldIndex, newIndex)
0101 }
0102 }
0103 TimerEdit {
0104 id: editor
0105 alertMode: editable
0106 value: time
0107 property int oldValue: 0
0108 onDigitModified: valueDelta => {
0109 set(value + valueDelta)
0110 }
0111 function set(newValue) {
0112 timeListModel.setTimer(index, (newValue).toString())
0113 }
0114 Component.onCompleted: editable = (value === 0)
0115 }
0116 QQC2.Label {
0117 id: hintText
0118 visible: editor.editable
0119 text: i18n("Scroll over digits to change time")
0120 textFormat: Text.PlainText
0121 anchors.verticalCenter: parent.verticalCenter
0122 }
0123 }
0124 actions: [
0125 Kirigami.Action {
0126 text: i18n("Apply")
0127 icon.name: "dialog-ok-apply"
0128 visible: editor.editable
0129 onTriggered: {
0130 editor.editable = false
0131 }
0132 },
0133 Kirigami.Action {
0134 text: i18n("Cancel")
0135 icon.name: "dialog-cancel"
0136 visible: editor.editable
0137 onTriggered: {
0138 editor.editable = false
0139 editor.set(editor.oldValue)
0140 }
0141 },
0142 Kirigami.Action {
0143 text: i18n("Edit")
0144 icon.name: "edit-entry"
0145 visible: editor.editable === false
0146 onTriggered: {
0147 editor.oldValue = editor.value
0148 editor.editable = true
0149 }
0150 },
0151 Kirigami.Action {
0152 text: i18n("Delete")
0153 icon.name: "entry-delete"
0154 visible: editor.editable === false
0155 onTriggered: {
0156 timeListModel.removeTimer(index)
0157 }
0158 }
0159 ]
0160 }
0161 }
0162 }
0163