Plasma-framework

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: "list-add"
67 }
69 x: control.mirrored ? parent.width - width : 0
70 z: -1
71 anchors {
72 top: parent.top
73 bottom: parent.bottom
74 topMargin: bgLoader.topMargin
75 bottomMargin: bgLoader.bottomMargin
76 }
77 implicitWidth: naturalSize.width
78 implicitHeight: implicitWidth
79 elementId: "vertical-line"
80 svg: lineSvg
81 }
82 }
83
84 down.indicator: P.FlatButtonBackground {
85 x: control.mirrored ? parent.width - width : 0
86 implicitHeight: Kirigami.Units.gridUnit + bgLoader.topMargin + bgLoader.bottomMargin
87 implicitWidth: Kirigami.Units.gridUnit + bgLoader.leftMargin + bgLoader.rightMargin
88 height: parent.height
89 hovered: control.down.hovered
90 pressed: control.down.pressed
91 focused: false
92 checked: false
93 Kirigami.Icon {
94 anchors.centerIn: parent
95 implicitWidth: Kirigami.Units.iconSizes.sizeForLabels
96 implicitHeight: Kirigami.Units.iconSizes.sizeForLabels
97 source: "list-remove"
98 }
100 x: control.mirrored ? 0 : parent.width - width
101 z: -1
102 anchors {
103 top: parent.top
104 bottom: parent.bottom
105 topMargin: bgLoader.topMargin
106 bottomMargin: bgLoader.bottomMargin
107 }
108 implicitWidth: naturalSize.width
109 implicitHeight: implicitWidth
110 elementId: "vertical-line"
111 svg: lineSvg
112 }
113 }
114
115 contentItem: T.TextField {
116 id: textField
117 opacity: enabled ? 1 : 0.5
118 implicitWidth: Math.ceil(contentWidth) + leftPadding + rightPadding
119 implicitHeight: Math.ceil(contentHeight) + topPadding + bottomPadding
120 text: control.displayText
121 font: control.font
122 Kirigami.Theme.colorSet: Kirigami.Theme.View
123 Kirigami.Theme.inherit: false
124 color: Kirigami.Theme.textColor
125 selectionColor: Kirigami.Theme.highlightColor
126 selectedTextColor: Kirigami.Theme.highlightedTextColor
127 horizontalAlignment: Qt.AlignHCenter
128 verticalAlignment: Qt.AlignVCenter
129 readOnly: !control.editable
130 validator: control.validator
131 inputMethodHints: control.inputMethodHints
132 selectByMouse: true
133 hoverEnabled: false
134 }
135
136 background: Loader {
137 id: bgLoader
138 // Anchors are needed because the Loader tries to resize itself on load
139 anchors {
140 fill: parent
141 topMargin: control.topInset
142 // Anchors will automirrot, inset won't, so we wnt the left stays left regardless of the layout
143 leftMargin: LayoutMirroring.enabled ? control.rightInset : control.leftInset
144 rightMargin: LayoutMirroring.enabled ? control.leftInset : control.rightInset
145 bottomMargin: control.bottomInset
146 }
147 readonly property real leftMargin: item.leftMargin
148 readonly property real rightMargin: item.rightMargin
149 readonly property real topMargin: item.topMargin
150 readonly property real bottomMargin: item.bottomMargin
151 sourceComponent: control.editable ? editableBg : noneditableBg
152 Component {
153 id: noneditableBg
154 P.RaisedButtonBackground {
155 hovered: control.hovered
156 focused: control.visualFocus || (control.contentItem.activeFocus && (
157 control.contentItem.focusReason == Qt.TabFocusReason ||
158 control.contentItem.focusReason == Qt.BacktabFocusReason ||
159 control.contentItem.focusReason == Qt.ShortcutFocusReason
160 ))
161 checked: false
162 pressed: false
163 }
164 }
165 Component {
166 id: editableBg
168 readonly property real leftMargin: margins.left
169 readonly property real rightMargin: margins.right
170 readonly property real topMargin: margins.top
171 readonly property real bottomMargin: margins.bottom
172 imagePath: "widgets/lineedit"
173 prefix: "base"
175 anchors {
176 fill: parent
177 leftMargin: -margins.left
178 topMargin: -margins.top
179 rightMargin: -margins.right
180 bottomMargin: -margins.bottom
181 }
182 imagePath: "widgets/lineedit"
183 prefix: "hover"
184 visible: opacity > 0
185 opacity: control.hovered
186 Behavior on opacity {
187 enabled: control.hovered && Kirigami.Units.longDuration > 0
188 NumberAnimation {
189 duration: Kirigami.Units.longDuration
190 easing.type: Easing.OutCubic
191 }
192 }
193 }
195 property bool visualFocus: control.visualFocus || (control.contentItem.activeFocus
196 && (control.contentItem.focusReason == Qt.TabFocusReason ||
197 control.contentItem.focusReason == Qt.BacktabFocusReason ||
198 control.contentItem.focusReason == Qt.ShortcutFocusReason)
199 )
200 z: lineEditSvg.hasElement("hint-focus-over-base") ? 0 : -1
201 anchors {
202 fill: parent
203 leftMargin: -margins.left
204 topMargin: -margins.top
205 rightMargin: -margins.right
206 bottomMargin: -margins.bottom
207 }
208 imagePath: "widgets/lineedit"
209 prefix: visualFocus && lineEditSvg.hasElement("focusframe-center") ? "focusframe" : "focus"
210 visible: opacity > 0
211 opacity: visualFocus || control.activeFocus || control.contentItem.activeFocus
212 Behavior on opacity {
213 enabled: Kirigami.Units.longDuration > 0
214 NumberAnimation {
215 duration: Kirigami.Units.longDuration
216 easing.type: Easing.OutCubic
217 }
218 }
219 }
220 KSvg.Svg {
221 id: lineEditSvg
222 imagePath: "widgets/lineedit"
223 }
224 }
225 }
226 }
227}
Q_INVOKABLE bool hasElement(const QString &elementName) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:54:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.