-
Notifications
You must be signed in to change notification settings - Fork 3
/
TextField.qml
48 lines (38 loc) · 995 Bytes
/
TextField.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Version 6
import QtQuick
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
QQC2.TextField {
id: textField
property string configKey: ''
readonly property string configValue: configKey ? plasmoid.configuration[configKey] : ""
onConfigValueChanged: {
if (!focus && text != configValue) {
text = configValue
}
}
text: configValue
onTextChanged: serializeTimer.start()
property string defaultValue: ""
rightPadding: clearButton.width + Kirigami.Units.smallSpacing
property alias clearButton: clearButton
QQC2.ToolButton {
id: clearButton
visible: textField.text != textField.defaultValue
icon.name: "edit-clear"
onClicked: textField.text = defaultValue
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
width: implicitBackgroundHeight
}
Timer { // throttle
id: serializeTimer
interval: 300
onTriggered: {
if (configKey) {
plasmoid.configuration[configKey] = textField.text
}
}
}
}