Warning, /plasma/latte-dock/declarativeimports/components/TextField.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003 SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 import QtQuick 2.0
0006 import QtQuick.Layouts 1.3
0007 import QtQuick.Controls 1.4
0008
0009 import org.kde.plasma.components 2.0 as PlasmaComponents
0010
0011 PlasmaComponents.TextField {
0012 id: textField
0013
0014 validator: IntValidator {
0015 bottom: minValue
0016 top: maxValue
0017 }
0018
0019 onTextChanged: {
0020 if (text.trim() === minValue.toString())
0021 text = ""
0022 }
0023
0024 font.italic: true
0025 inputMethodHints: Qt.ImhDigitsOnly
0026 placeholderText: i18n("none")
0027 horizontalAlignment: Text.AlignLeft
0028
0029 readonly property int implicitWidth: internalContent.width + theme.mSize(theme.defaultFont).width * 3.5
0030
0031 readonly property int value: text === "" ? minValue : parseInt(text)
0032 property int step: 100
0033 property int minValue: 0
0034 property int maxValue: 3000
0035
0036 function increment() {
0037 var val = text === "" ? minValue : parseInt(text)
0038 text = Math.min(val + step, maxValue).toString()
0039 }
0040
0041 function decrement() {
0042 var val = text === "" ? minValue : parseInt(text)
0043 val = Math.max(val - step, minValue)
0044 text = val === minValue ? "" : val.toString()
0045 }
0046
0047 RowLayout {
0048 id: internalContent
0049 spacing: 0
0050 anchors.top: parent.top
0051 anchors.bottom: parent.bottom
0052 anchors.right: parent.right
0053
0054 LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
0055 LayoutMirroring.childrenInherit: true
0056
0057 PlasmaComponents.Label {
0058 Layout.alignment: Qt.AlignVCenter
0059 color: textField.textColor
0060 text: i18n("ms.")
0061 font.italic: true
0062 opacity: value === 0 ? 0 : 0.6
0063 }
0064 PlasmaComponents.Button {
0065 id: downButton
0066
0067 Layout.fillHeight: true
0068 Layout.preferredWidth: height
0069 Layout.maximumWidth: height
0070 Layout.leftMargin: Qt.application.layoutDirection === Qt.RightToLeft ? 0 : 0.7 * theme.mSize(theme.defaultFont).width
0071 Layout.rightMargin: Qt.application.layoutDirection === Qt.RightToLeft ? 0.7 * theme.mSize(theme.defaultFont).width : 0
0072
0073 text: "-"
0074 onClicked: decrement()
0075 }
0076 PlasmaComponents.Button {
0077 id: upButton
0078
0079 Layout.fillHeight: true
0080 Layout.preferredWidth: height
0081 Layout.maximumWidth: height
0082 text: "+"
0083 onClicked: increment()
0084 }
0085 }
0086
0087 Timer {
0088 id: holdPressed
0089 running: upButton.pressed || downButton.pressed
0090 interval: 200
0091 repeat: true
0092
0093 onRunningChanged: {
0094 if (!running)
0095 interval = 200
0096 }
0097
0098 onTriggered: {
0099 if (interval === 200)
0100 interval = 150
0101 else if (upButton.pressed)
0102 increment()
0103 else
0104 decrement()
0105 }
0106 }
0107
0108 MouseArea {
0109 anchors.fill: parent
0110 acceptedButtons: Qt.MiddleButton
0111
0112 onWheel: {
0113 var angle = wheel.angleDelta.y / 8
0114
0115 if (angle > 0) {
0116 increment()
0117 } else if (angle < 0) {
0118 decrement()
0119 }
0120 }
0121 }
0122 }