aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/basic/SpinBox.qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/quickcontrols/basic/SpinBox.qml')
-rw-r--r--src/quickcontrols/basic/SpinBox.qml98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/quickcontrols/basic/SpinBox.qml b/src/quickcontrols/basic/SpinBox.qml
new file mode 100644
index 0000000000..cf4315e910
--- /dev/null
+++ b/src/quickcontrols/basic/SpinBox.qml
@@ -0,0 +1,98 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+import QtQuick
+import QtQuick.Controls.impl
+import QtQuick.Templates as T
+
+T.SpinBox {
+ id: control
+
+ // Note: the width of the indicators are calculated into the padding
+ implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
+ contentItem.implicitWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
+ implicitContentHeight + topPadding + bottomPadding,
+ up.implicitIndicatorHeight, down.implicitIndicatorHeight)
+
+ leftPadding: padding + (control.mirrored ? (up.indicator ? up.indicator.width : 0) : (down.indicator ? down.indicator.width : 0))
+ rightPadding: padding + (control.mirrored ? (down.indicator ? down.indicator.width : 0) : (up.indicator ? up.indicator.width : 0))
+
+ validator: IntValidator {
+ locale: control.locale.name
+ bottom: Math.min(control.from, control.to)
+ top: Math.max(control.from, control.to)
+ }
+
+ contentItem: TextInput {
+ z: 2
+ text: control.displayText
+ clip: width < implicitWidth
+ padding: 6
+
+ font: control.font
+ color: control.palette.text
+ selectionColor: control.palette.highlight
+ selectedTextColor: control.palette.highlightedText
+ horizontalAlignment: Qt.AlignHCenter
+ verticalAlignment: Qt.AlignVCenter
+
+ readOnly: !control.editable
+ validator: control.validator
+ inputMethodHints: control.inputMethodHints
+
+ Rectangle {
+ width: parent.width
+ height: parent.height
+ visible: control.activeFocus
+ color: "transparent"
+ border.color: control.palette.highlight
+ border.width: 2
+ }
+ }
+
+ up.indicator: Rectangle {
+ x: control.mirrored ? 0 : control.width - width
+ height: control.height
+ implicitWidth: 40
+ implicitHeight: 40
+ color: control.up.pressed ? control.palette.mid : control.palette.button
+
+ Rectangle {
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ width: parent.width / 3
+ height: 2
+ color: enabled ? control.palette.buttonText : control.palette.mid
+ }
+ Rectangle {
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ width: 2
+ height: parent.width / 3
+ color: enabled ? control.palette.buttonText : control.palette.mid
+ }
+ }
+
+ down.indicator: Rectangle {
+ x: control.mirrored ? parent.width - width : 0
+ height: control.height
+ implicitWidth: 40
+ implicitHeight: 40
+ color: control.down.pressed ? control.palette.mid : control.palette.button
+
+ Rectangle {
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ width: parent.width / 3
+ height: 2
+ color: enabled ? control.palette.buttonText : control.palette.mid
+ }
+ }
+
+ background: Rectangle {
+ implicitWidth: 140
+ color: enabled ? control.palette.base : control.palette.button
+ border.color: control.palette.button
+ }
+}