1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-02-04 01:47:31 +03:00

123 lines
3.2 KiB
QML
Raw Normal View History

/*
2021-05-27 15:01:00 +00:00
SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls 1.4
import org.kde.plasma.components 2.0 as PlasmaComponents
2017-01-09 12:42:59 -05:00
PlasmaComponents.TextField {
id: textField
2017-01-09 12:48:03 -05:00
validator: IntValidator {
bottom: minValue
top: maxValue
}
onTextChanged: {
if (text.trim() === minValue.toString())
text = ""
}
font.italic: true
inputMethodHints: Qt.ImhDigitsOnly
placeholderText: i18n("none")
2017-11-28 20:22:25 +02:00
horizontalAlignment: Text.AlignLeft
2017-01-09 12:48:03 -05:00
2021-01-24 20:44:39 +02:00
readonly property int implicitWidth: internalContent.width + theme.mSize(theme.defaultFont).width * 3.5
readonly property int value: text === "" ? minValue : parseInt(text)
property int step: 100
property int minValue: 0
property int maxValue: 3000
function increment() {
var val = text === "" ? minValue : parseInt(text)
text = Math.min(val + step, maxValue).toString()
}
function decrement() {
var val = text === "" ? minValue : parseInt(text)
val = Math.max(val - step, minValue)
text = val === minValue ? "" : val.toString()
}
2017-01-09 12:42:59 -05:00
RowLayout {
id: internalContent
spacing: 0
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
2017-01-09 12:48:03 -05:00
2017-11-28 20:22:25 +02:00
LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
LayoutMirroring.childrenInherit: true
2017-01-09 12:42:59 -05:00
PlasmaComponents.Label {
Layout.alignment: Qt.AlignVCenter
color: textField.textColor
text: i18n("ms.")
font.italic: true
opacity: value === 0 ? 0 : 0.6
2017-01-09 12:48:03 -05:00
}
2017-01-09 12:42:59 -05:00
PlasmaComponents.Button {
id: downButton
2017-01-09 12:42:59 -05:00
Layout.fillHeight: true
Layout.preferredWidth: height
Layout.maximumWidth: height
2017-11-28 20:22:25 +02:00
Layout.leftMargin: Qt.application.layoutDirection === Qt.RightToLeft ? 0 : 0.7 * theme.mSize(theme.defaultFont).width
Layout.rightMargin: Qt.application.layoutDirection === Qt.RightToLeft ? 0.7 * theme.mSize(theme.defaultFont).width : 0
2017-01-09 12:48:03 -05:00
text: "-"
onClicked: decrement()
}
2017-01-09 12:42:59 -05:00
PlasmaComponents.Button {
id: upButton
2017-01-09 12:42:59 -05:00
Layout.fillHeight: true
Layout.preferredWidth: height
Layout.maximumWidth: height
2017-01-09 12:48:03 -05:00
text: "+"
onClicked: increment()
}
}
Timer {
id: holdPressed
running: upButton.pressed || downButton.pressed
interval: 200
repeat: true
onRunningChanged: {
if (!running)
interval = 200
}
onTriggered: {
if (interval === 200)
interval = 150
else if (upButton.pressed)
increment()
else
decrement()
}
}
2017-01-09 12:48:03 -05:00
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.MiddleButton
onWheel: {
var angle = wheel.angleDelta.y / 8
2017-01-09 12:48:03 -05:00
if (angle > 0) {
increment()
2017-01-09 12:48:03 -05:00
} else if (angle < 0) {
decrement()
}
}
}
}