Libplasma

SpinBox.qml
1/*
2 * SPDX-FileCopyrightText: 2017 Marco Martin <notmart@gmail.com>
3 * SPDX-FileCopyrightText: 2020 Nate Graham <nate@kde.org>
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7import QtQuick
8import QtQuick.Controls
9import QtQuick.Templates as T
10import org.kde.ksvg as KSvg
11//NOTE: importing PlasmaCore is necessary in order to make KSvg load the current Plasma Theme
12import org.kde.plasma.core as PlasmaCore
13import org.kde.plasma.components as PlasmaComponents3
14import org.kde.kirigami as Kirigami
15import "private" as P
16
17T.SpinBox {
18 id: control
19
20 implicitWidth: Math.max(
21 implicitBackgroundWidth + leftInset + rightInset,
22 Math.max(implicitContentWidth, Kirigami.Units.gridUnit)
23 + spacing * 2 + leftPadding + rightPadding,
24 up.implicitIndicatorWidth + down.implicitIndicatorWidth
25 )
26 implicitHeight: Math.max(
27 implicitBackgroundHeight + topInset + bottomInset,
28 implicitContentHeight + topPadding + bottomPadding,
29 up.implicitIndicatorHeight,
30 down.implicitIndicatorHeight
31 )
32
33 leftPadding: !mirrored ? down.implicitIndicatorWidth : up.implicitIndicatorWidth
34 rightPadding: mirrored ? down.implicitIndicatorWidth : up.implicitIndicatorWidth
35 topPadding: bgLoader.topMargin
36 bottomPadding: bgLoader.bottomMargin
37 spacing: bgLoader.leftMargin
38 editable: true
39 inputMethodHints: Qt.ImhFormattedNumbersOnly
40 validator: IntValidator {
41 locale: control.locale.name
42 bottom: Math.min(control.from, control.to)
43 top: Math.max(control.from, control.to)
44 }
45 wheelEnabled: true
46 hoverEnabled: Qt.styleHints.useHoverEffects
47
48 KSvg.Svg {
49 id: lineSvg
50 imagePath: "widgets/line"
51 }
52
53 up.indicator: P.FlatButtonBackground {
54 x: control.mirrored ? 0 : parent.width - width
55 implicitHeight: Kirigami.Units.gridUnit + bgLoader.topMargin + bgLoader.bottomMargin
56 implicitWidth: Kirigami.Units.gridUnit + bgLoader.leftMargin + bgLoader.rightMargin
57 height: parent.height
58 hovered: control.up.hovered
59 pressed: control.up.pressed
60 focused: false
61 checked: false
62 Kirigami.Icon {
63 anchors.centerIn: parent
64 implicitWidth: Kirigami.Units.iconSizes.sizeForLabels
65 implicitHeight: Kirigami.Units.iconSizes.sizeForLabels
66 source: "value-increase"
67 fallback: "list-add"
68 }
70 x: control.mirrored ? parent.width - width : 0
71 z: -1
72 anchors {
73 top: parent.top
74 bottom: parent.bottom
75 topMargin: bgLoader.topMargin
76 bottomMargin: bgLoader.bottomMargin
77 }
78 implicitWidth: naturalSize.width
79 implicitHeight: implicitWidth
80 elementId: "vertical-line"
81 svg: lineSvg
82 }
83 }
84
85 down.indicator: P.FlatButtonBackground {
86 x: control.mirrored ? parent.width - width : 0
87 implicitHeight: Kirigami.Units.gridUnit + bgLoader.topMargin + bgLoader.bottomMargin
88 implicitWidth: Kirigami.Units.gridUnit + bgLoader.leftMargin + bgLoader.rightMargin
89 height: parent.height
90 hovered: control.down.hovered
91 pressed: control.down.pressed
92 focused: false
93 checked: false
94 Kirigami.Icon {
95 anchors.centerIn: parent
96 implicitWidth: Kirigami.Units.iconSizes.sizeForLabels
97 implicitHeight: Kirigami.Units.iconSizes.sizeForLabels
98 source: "value-decrease"
99 fallback: "list-remove"
100 }
101 KSvg.SvgItem {
102 x: control.mirrored ? 0 : parent.width - width
103 z: -1
104 anchors {
105 top: parent.top
106 bottom: parent.bottom
107 topMargin: bgLoader.topMargin
108 bottomMargin: bgLoader.bottomMargin
109 }
110 implicitWidth: naturalSize.width
111 implicitHeight: implicitWidth
112 elementId: "vertical-line"
113 svg: lineSvg
114 }
115 }
116
117 contentItem: T.TextField {
118 id: textField
119 opacity: enabled ? 1 : 0.5
120 implicitWidth: Math.ceil(contentWidth) + leftPadding + rightPadding
121 implicitHeight: Math.ceil(contentHeight) + topPadding + bottomPadding
122 text: control.displayText
123 font: control.font
124 Kirigami.Theme.colorSet: Kirigami.Theme.View
125 Kirigami.Theme.inherit: false
126 color: Kirigami.Theme.textColor
127 selectionColor: Kirigami.Theme.highlightColor
128 selectedTextColor: Kirigami.Theme.highlightedTextColor
129 horizontalAlignment: Qt.AlignHCenter
130 verticalAlignment: Qt.AlignVCenter
131 readOnly: !control.editable
132 validator: control.validator
133 inputMethodHints: control.inputMethodHints
134 selectByMouse: true
135 hoverEnabled: false
136 }
137
138 background: Loader {
139 id: bgLoader
140 // Anchors are needed because the Loader tries to resize itself on load
141 anchors {
142 fill: parent
143 topMargin: control.topInset
144 // Anchors will automirrot, inset won't, so we wnt the left stays left regardless of the layout
145 leftMargin: LayoutMirroring.enabled ? control.rightInset : control.leftInset
146 rightMargin: LayoutMirroring.enabled ? control.leftInset : control.rightInset
147 bottomMargin: control.bottomInset
148 }
149 readonly property real leftMargin: item.leftMargin
150 readonly property real rightMargin: item.rightMargin
151 readonly property real topMargin: item.topMargin
152 readonly property real bottomMargin: item.bottomMargin
153 sourceComponent: control.editable ? editableBg : noneditableBg
154 Component {
155 id: noneditableBg
156 P.RaisedButtonBackground {
157 hovered: control.hovered
158 focused: control.visualFocus || (control.contentItem.activeFocus && (
159 control.contentItem.focusReason == Qt.TabFocusReason ||
160 control.contentItem.focusReason == Qt.BacktabFocusReason ||
161 control.contentItem.focusReason == Qt.ShortcutFocusReason
162 ))
163 checked: false
164 pressed: false
165 }
166 }
167 Component {
168 id: editableBg
170 readonly property real leftMargin: margins.left
171 readonly property real rightMargin: margins.right
172 readonly property real topMargin: margins.top
173 readonly property real bottomMargin: margins.bottom
174 imagePath: "widgets/lineedit"
175 prefix: "base"
177 anchors {
178 fill: parent
179 leftMargin: -margins.left
180 topMargin: -margins.top
181 rightMargin: -margins.right
182 bottomMargin: -margins.bottom
183 }
184 imagePath: "widgets/lineedit"
185 prefix: "hover"
186 visible: opacity > 0
187 opacity: control.hovered
188 Behavior on opacity {
189 enabled: control.hovered && Kirigami.Units.longDuration > 0
190 NumberAnimation {
191 duration: Kirigami.Units.longDuration
192 easing.type: Easing.OutCubic
193 }
194 }
195 }
197 property bool visualFocus: control.visualFocus || (control.contentItem.activeFocus
198 && (control.contentItem.focusReason == Qt.TabFocusReason ||
199 control.contentItem.focusReason == Qt.BacktabFocusReason ||
200 control.contentItem.focusReason == Qt.ShortcutFocusReason)
201 )
202 z: lineEditSvg.hasElement("hint-focus-over-base") ? 0 : -1
203 anchors {
204 fill: parent
205 leftMargin: -margins.left
206 topMargin: -margins.top
207 rightMargin: -margins.right
208 bottomMargin: -margins.bottom
209 }
210 imagePath: "widgets/lineedit"
211 prefix: visualFocus && lineEditSvg.hasElement("focusframe-center") ? "focusframe" : "focus"
212 visible: opacity > 0
213 opacity: visualFocus || control.activeFocus || control.contentItem.activeFocus
214 Behavior on opacity {
215 enabled: Kirigami.Units.longDuration > 0
216 NumberAnimation {
217 duration: Kirigami.Units.longDuration
218 easing.type: Easing.OutCubic
219 }
220 }
221 }
222 KSvg.Svg {
223 id: lineEditSvg
224 imagePath: "widgets/lineedit"
225 }
226 }
227 }
228 }
229}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:10:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.