Warning, /plasma/kdeplasma-addons/applets/timer/package/contents/ui/TimerEdit.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 2.15
0008 import org.kde.plasma.plasmoid 2.0
0009 import org.kde.plasma.core as PlasmaCore
0010 import org.kde.ksvg 1.0 as KSvg
0011 import org.kde.kquickcontrolsaddons 2.0 as QtExtra
0012 import org.kde.plasma.private.timer 0.1 as TimerPlasmoid
0013
0014 Row {
0015 id: timerEdit
0016 property int value // time in seconds
0017 property bool editable: true
0018 // in alert mode 2nd set of digits from svg file will be drawn
0019 property bool alertMode: false
0020
0021 signal digitModified(int valueDelta)
0022
0023 QtObject {
0024 id: internal
0025 readonly property string digitSuffix: alertMode ? "_1" : ""
0026 // digits count include separators with 50% of digit width
0027 readonly property real digits: root.showSeconds ? 7 : 4.5;
0028 readonly property int digitH: (parent.height / 2) * digits < parent.width ? parent.height : parent.width / digits * 2
0029 readonly property int digitW: digitH / 2;
0030 property string valueString: "000000"
0031 }
0032
0033 Component {
0034 id: digit
0035 KSvg.SvgItem {
0036 property int meaning
0037 property int num
0038 readonly property int mouseWheelAngleThreshold: 5
0039 width: internal.digitW
0040 height: internal.digitH
0041
0042 activeFocusOnTab: true
0043 imagePath: "widgets/timer"
0044 elementId: num + internal.digitSuffix
0045
0046 Keys.onPressed: {
0047 switch (event.key) {
0048 case Qt.Key_Return:
0049 case Qt.Key_Enter:
0050 case Qt.Key_Space:
0051 case Qt.Key_Select:
0052 root.toggleTimer();
0053 break;
0054 case Qt.Key_Up:
0055 if (value + meaning < 24*60*60) {
0056 timerEdit.digitModified(meaning)
0057 }
0058 break;
0059 case Qt.Key_Down:
0060 if (value - meaning >= 0) {
0061 timerEdit.digitModified(-meaning)
0062 }
0063 break;
0064 case Qt.Key_Left:
0065 nextItemInFocusChain(false).forceActiveFocus(Qt.BacktabFocusReason);
0066 break;
0067 case Qt.Key_Right:
0068 nextItemInFocusChain(true).forceActiveFocus(Qt.TabFocusReason);
0069 break;
0070 default:
0071 return;
0072 }
0073 event.accepted = true;
0074 }
0075
0076 MouseArea {
0077 anchors.fill: parent
0078 enabled: editable
0079 propagateComposedEvents: true
0080
0081 onWheel: wheel => {
0082 wheel.accepted = true
0083 if (wheel.angleDelta.y > mouseWheelAngleThreshold) {
0084 if (value + meaning < 24*60*60) {
0085 timerEdit.digitModified(meaning)
0086 }
0087 } else if (wheel.angleDelta.y < -mouseWheelAngleThreshold) {
0088 if (value - meaning >= 0) {
0089 timerEdit.digitModified(-meaning)
0090 }
0091 }
0092 }
0093 }
0094 }
0095 }
0096
0097 Component {
0098 id: separator
0099 KSvg.SvgItem {
0100 width: internal.digitW / 2;
0101 height: internal.digitH;
0102 imagePath: "widgets/timer"
0103 elementId: "separator" + internal.digitSuffix
0104 }
0105 }
0106
0107 // Following 8 loaders will prepare all elements
0108 // to display time in format "hh:mm:ss"
0109
0110 Loader {
0111 id: hour1
0112 sourceComponent: digit
0113 onLoaded: {
0114 item.meaning = 60*60*10 //10h
0115 item.num = internal.valueString[0]
0116 }
0117 }
0118 Loader {
0119 id: hour2
0120 sourceComponent: digit
0121 onLoaded: {
0122 item.meaning = 60*60 //1h
0123 item.num = internal.valueString[1]
0124 }
0125 }
0126
0127 Loader { sourceComponent: separator } // ":"
0128
0129 Loader {
0130 id: minute1
0131 sourceComponent: digit
0132 onLoaded: {
0133 item.meaning = 600 //10min
0134 item.num = internal.valueString[2]
0135 }
0136 }
0137 Loader {
0138 id: minute2
0139 sourceComponent: digit
0140 onLoaded: {
0141 item.meaning = 60 //1min
0142 item.num = internal.valueString[3]
0143 }
0144 }
0145
0146 Loader { sourceComponent: root.showSeconds ? separator : undefined } // ":"
0147
0148 Loader {
0149 id: second1
0150 sourceComponent: root.showSeconds ? digit : undefined
0151 onLoaded: {
0152 item.meaning = 10 //10s
0153 item.num = internal.valueString[4]
0154 }
0155 }
0156 Loader {
0157 id: second2
0158 sourceComponent: root.showSeconds ? digit : undefined
0159 onLoaded: {
0160 item.meaning = 1 //1s
0161 item.num = internal.valueString[5]
0162 }
0163 }
0164
0165 onValueChanged: {
0166 // update all 6 digits in one signal handler
0167 internal.valueString = TimerPlasmoid.Timer.secondsToString(value, "hhmmss")
0168 if (hour1.item === null) return
0169 hour1.item.num = internal.valueString[0]
0170 hour2.item.num = internal.valueString[1]
0171 minute1.item.num = internal.valueString[2]
0172 minute2.item.num = internal.valueString[3]
0173 second1.item.num = internal.valueString[4]
0174 second2.item.num = internal.valueString[5]
0175 }
0176 }
0177