2017-01-09 15:43:35 +02:00
/ *
2021-05-27 15:01:00 +00:00
SPDX - FileCopyrightText: 2019 Michail Vourlakos < mvourlakos @ gmail . com >
SPDX - License - Identifier: GPL - 2.0 - or - later
2017-01-09 15:43:35 +02:00
* /
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 {
2017-01-09 15:43:35 +02:00
id: textField
2017-01-09 16:27:58 -05:00
2017-01-09 12:48:03 -05:00
validator: IntValidator {
bottom: minValue
top: maxValue
}
2017-01-09 16:27:58 -05:00
onTextChanged: {
if ( text . trim ( ) === minValue . toString ( ) )
text = ""
}
2017-01-09 15:43:35 +02:00
font.italic: true
2017-01-09 16:27:58 -05:00
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
2017-01-09 15:43:35 +02:00
2017-01-09 16:27:58 -05:00
readonly property int value: text === "" ? minValue : parseInt ( text )
2017-01-09 15:43:35 +02:00
property int step: 100
property int minValue: 0
property int maxValue: 3000
2017-01-09 16:27:58 -05:00
function increment ( ) {
var val = text === "" ? minValue : parseInt ( text )
text = Math . min ( val + step , maxValue ) . toString ( )
2017-01-09 15:43:35 +02:00
}
2017-01-09 16:27:58 -05:00
function decrement ( ) {
var val = text === "" ? minValue : parseInt ( text )
val = Math . max ( val - step , minValue )
text = val === minValue ? "" : val . toString ( )
}
2017-01-09 15:43:35 +02:00
2017-01-09 12:42:59 -05:00
RowLayout {
id: internalContent
spacing: 0
anchors.top: parent . top
anchors.bottom: parent . bottom
2017-01-09 15:43:35 +02:00
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
2017-01-09 15:43:35 +02:00
color: textField . textColor
text: i18n ( "ms." )
font.italic: true
2017-01-09 16:27:58 -05:00
opacity: value === 0 ? 0 : 0.6
2017-01-09 12:48:03 -05:00
}
2017-01-09 12:42:59 -05:00
PlasmaComponents . Button {
2017-01-09 16:27:58 -05:00
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: "-"
2017-01-09 16:27:58 -05:00
onClicked: decrement ( )
2017-01-09 15:43:35 +02:00
}
2017-01-09 12:42:59 -05:00
PlasmaComponents . Button {
2017-01-09 16:27:58 -05:00
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: "+"
2017-01-09 16:27:58 -05:00
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 15:43:35 +02:00
}
}
2017-01-09 12:48:03 -05:00
MouseArea {
2017-01-09 15:43:35 +02:00
anchors.fill: parent
acceptedButtons: Qt . MiddleButton
onWheel: {
var angle = wheel . angleDelta . y / 8
2017-01-09 12:48:03 -05:00
if ( angle > 0 ) {
2017-01-09 16:27:58 -05:00
increment ( )
2017-01-09 12:48:03 -05:00
} else if ( angle < 0 ) {
2017-01-09 16:27:58 -05:00
decrement ( )
2017-01-09 15:43:35 +02:00
}
}
}
}