Debian Codegraph @

src/imports/Components/Themes/Ambiance/1.3/ComboButtonStyle.qml

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components 1.3
19 import Lomiri.Components.Styles 1.3 as Style
20
21 Style.ComboButtonStyle {
22 id: comboStyle
23
24 // configurations
25 dropDownWidth: units.gu(5)
26 comboListMargin: units.gu(0.8)
27 comboListHolder: comboListContent
28 comboListPanel: panelItem
29 defaultColor: mainButton.defaultColor
30 defaultGradient: mainButton.defaultGradient
31 defaultDropdownColor: mainButton.defaultColor
32 defaultFont: mainButton.defaultFont
33
34 width: styledItem.width
35 height: styledItem.collapsedHeight
36
37 implicitWidth: mainButton.implicitWidth
38 implicitHeight: mainButton.implicitHeight
39
40 LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
41 LayoutMirroring.childrenInherit: true
42
43 Item {
44 id: mainButton
45
46 property real minimumWidth: units.gu(36)
47 property real horizontalPadding: units.gu(4)
48 property color defaultColor: theme.palette.normal.foreground
49 property font defaultFont: Qt.font({family: "Ubuntu", pixelSize: FontUtils.sizeToPixels("medium")})
50 property Gradient defaultGradient: null
51 property real buttonFaceOffset: -dropDownWidth/2
52 property bool stroke: false
53
54 /*!
55 The property overrides the button's default background with an item. This
56 item can be used by derived styles to reuse the ButtonStyle and override
57 the default coloured background with an image or any other drawing.
58 The default value is null.
59 */
60 property Item backgroundSource: comboFace
61
62 anchors {
63 left: parent.left
64 top: parent.top
65 right: parent.right
66 }
67 width: styledItem.width
68 height: styledItem.collapsedHeight
69 implicitWidth: Math.max(
70 minimumWidth, foreground.implicitWidth + 2 * mainButton.horizontalPadding
71 )
72 implicitHeight: units.gu(4)
73
74 LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
75 LayoutMirroring.childrenInherit: true
76
77 LomiriShape {
78 id: background
79 anchors.fill: parent
80 borderSource: "radius_idle.sci" // Deprecated, use a dedicated shape.
81 visible: mainButton.stroke ? false : ((backgroundColor.a != 0.0) || mainButton.backgroundSource)
82 source: mainButton.backgroundSource
83
84 backgroundColor: defaultColor
85 backgroundMode: LomiriShape.SolidColor
86 opacity: styledItem.enabled ? 1.0 : 0.6
87 }
88
89 Item {
90 id: foreground
91
92 property string iconPosition: styledItem.iconPosition
93 property real iconSize: units.gu(2)
94 property real spacing: mainButton.horizontalPadding
95 property bool hasIcon: styledItem.iconSource != ""
96 property bool hasText: styledItem.text != ""
97
98 anchors {
99 centerIn: parent
100 horizontalCenterOffset: mainButton.buttonFaceOffset
101 }
102 transformOrigin: Item.Top
103 width: parent.width - 2*mainButton.horizontalPadding
104 implicitHeight: Math.max(foregroundIcon.height, foregroundLabel.height)
105 scale: styledItem.pressed ? 0.98 : 1.0
106 Behavior on scale {
107 NumberAnimation {
108 duration: LomiriAnimation.SnapDuration
109 easing.type: Easing.Linear
110 }
111 }
112 state: foreground.hasIcon && hasText ? iconPosition : "center"
113
114 Icon {
115 id: foregroundIcon
116 visible: foreground.hasIcon
117 anchors.verticalCenter: parent.verticalCenter
118 width: foreground.iconSize
119 height: foreground.iconSize
120 color: foregroundLabel.color
121 source: styledItem.iconSource
122 }
123
124 Label {
125 id: foregroundLabel
126 anchors.verticalCenter: parent.verticalCenter
127 elide: Text.ElideRight
128 color: theme.palette.normal.foregroundText
129 font: styledItem.font
130 text: styledItem.text
131 }
132
133 states: [
134 State {
135 name: "left"
136 AnchorChanges {
137 target: foregroundIcon
138 anchors.left: foreground.left
139 }
140 AnchorChanges {
141 target: foregroundLabel
142 anchors.left: foregroundIcon.right
143 }
144 PropertyChanges {
145 target: foregroundLabel
146 anchors.leftMargin: spacing
147 width: foreground.width - foregroundIcon.width - spacing
148 }
149 PropertyChanges {
150 target: foreground
151 implicitWidth: foregroundIcon.implicitWidth + spacing + foregroundLabel.implicitWidth
152 }
153 },
154 State {
155 name: "right"
156 AnchorChanges {
157 target: foregroundIcon
158 anchors.right: foreground.right
159 }
160 AnchorChanges {
161 target: foregroundLabel
162 anchors.right: foregroundIcon.left
163 }
164 PropertyChanges {
165 target: foregroundLabel
166 anchors.rightMargin: spacing
167 width: foreground.width - foregroundIcon.width - spacing
168 }
169 PropertyChanges {
170 target: foreground
171 implicitWidth: foregroundIcon.implicitWidth + spacing + foregroundLabel.implicitWidth
172 }
173 },
174 State {
175 name: "center"
176 AnchorChanges {
177 target: foregroundIcon
178 anchors.horizontalCenter: foreground.horizontalCenter
179 }
180 AnchorChanges {
181 target: foregroundLabel
182 anchors.horizontalCenter: foreground.horizontalCenter
183 }
184 PropertyChanges {
185 target: foregroundLabel
186 width: Math.min(foregroundLabel.implicitWidth, foreground.width)
187 }
188 PropertyChanges {
189 target: foreground
190 implicitWidth: foreground.hasText ? foregroundLabel.implicitWidth : foregroundIcon.implicitWidth
191 }
192 }
193 ]
194 }
195
196 ShaderEffectSource {
197 id: comboFace
198 sourceItem: content
199 hideSource: true
200 // FIXME: visible: false prevents rendering so make it a nearly
201 // transparent 1x1 pixel instead
202 opacity: 0.01
203 width: 1
204 height: 1
205 }
206
207 Item {
208 id: content
209 width: mainButton.width
210 height: mainButton.height
211
212 // button background
213 Rectangle {
214 anchors {
215 fill: parent
216 rightMargin: comboStyle.dropDownWidth
217 }
218 color: defaultColor
219 }
220
221 Rectangle {
222 id: dropDownButton
223 objectName: "combobutton_dropdown_visuals"
224 anchors {
225 right: parent.right
226 top: parent.top
227 bottom: parent.bottom
228 }
229 width: comboStyle.dropDownWidth
230 color: defaultDropdownColor
231 Icon {
232 anchors.centerIn: parent
233 height: parent.height / 2
234 width: height
235 name: styledItem.expanded? "up" : "down"
236 color: foregroundLabel.color
237 }
238 }
239 }
240
241 FocusShape {
242 }
243 }
244
245 Item {
246 id: panelItem
247 objectName: "combobutton_combopanel"
248 anchors {
249 left: parent.left
250 top: mainButton.bottom
251 right: parent.right
252 }
253 // Hide panel to suppress keyboard input including (Shift)Tab
254 visible: styledItem.expanded && (styledItem.comboList.length > 0)
255
256 ShaderEffectSource {
257 id: listContent
258 sourceItem: comboListContent
259 hideSource: true
260 // FIXME: visible: false prevents rendering so make it a nearly
261 // transparent 1x1 pixel instead
262 opacity: 0.01
263 width: 1
264 height: 1
265 }
266 Rectangle {
267 id: comboListContent
268 anchors {
269 fill: parent
270 topMargin: comboListMargin
271 }
272 clip: true
273 color: defaultDropdownColor
274 }
275
276 LomiriShape {
277 id: shape
278 anchors {
279 fill: parent
280 topMargin: comboListMargin
281 }
282 source: listContent
283 }
284
285 Behavior on height {
286 NumberAnimation {
287 duration: LomiriAnimation.FastDuration
288 easing: LomiriAnimation.StandardEasing
289 }
290 }
291 Behavior on opacity {
292 NumberAnimation {
293 duration: LomiriAnimation.FastDuration
294 easing: LomiriAnimation.StandardEasing
295 }
296 }
297 }
298 }