Merge lp:~tpeeters/ubuntu-ui-toolkit/littleSwitch into lp:ubuntu-ui-toolkit/staging

Proposed by Tim Peeters
Status: Merged
Approved by: Cris Dywan
Approved revision: 1331
Merged at revision: 1321
Proposed branch: lp:~tpeeters/ubuntu-ui-toolkit/littleSwitch
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 260 lines (+133/-44)
2 files modified
modules/Ubuntu/Components/Themes/Ambiance/SwitchStyle.qml (+132/-43)
modules/Ubuntu/Components/Themes/Ambiance/qmldir (+1/-1)
To merge this branch: bzr merge lp:~tpeeters/ubuntu-ui-toolkit/littleSwitch
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Cris Dywan Approve
Review via email: mp+240985@code.launchpad.net

Commit message

Various tweaks to SwitchStyle:
- Scaling of icons when changing the size of the Switch
- Smaller default Switch size
- Use icons from theme
- Make check/uncheck animation faster
- Prevent animations on width change (during initialization)
- Expose SwitchStyle in Themes.Ambience
- Add all visualization parameters as properties to SwitchStyle.

To post a comment you must log in.
1331. By Tim Peeters

optimize iconSize computation

Revision history for this message
Tim Peeters (tpeeters) wrote :
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

52 + property color uncheckedThumbColor: Qt.rgba(0, 0, 0, 0.2)

Please don't do this. See bug 1389991 for why.

review: Needs Fixing
Revision history for this message
Tim Peeters (tpeeters) wrote :

It is the same color that we have now (and had for ages):

151 - color: styledItem.checked ? UbuntuColors.green
152 - : Qt.rgba(0, 0, 0, 0.2)

It is not the background color, but the unchecked thumb color, which goes on top of the background color, which is not transparent:

42 + property color backgroundColor: Theme.palette.normal.base

Revision history for this message
Cris Dywan (kalikiana) wrote :

Also, is the looks expected to be the same or different? Right now it's visibly changed.

Revision history for this message
Tim Peeters (tpeeters) wrote :

> Also, is the looks expected to be the same or different? Right now it's
> visibly changed.

See the linked bugs. The new switch must be smaller, the icons are updated, and the animation speed is faster.

Revision history for this message
Tim Peeters (tpeeters) wrote :

> > Also, is the looks expected to be the same or different? Right now it's
> > visibly changed.
>
> See the linked bugs. The new switch must be smaller, the icons are updated,
> and the animation speed is faster.

Also see the commit message :)

Revision history for this message
Cris Dywan (kalikiana) wrote :

Thanks for the clarifications. Looks very sweet!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/Themes/Ambiance/SwitchStyle.qml'
2--- modules/Ubuntu/Components/Themes/Ambiance/SwitchStyle.qml 2014-07-21 11:44:25 +0000
3+++ modules/Ubuntu/Components/Themes/Ambiance/SwitchStyle.qml 2014-11-06 21:04:28 +0000
4@@ -20,37 +20,124 @@
5 Item {
6 id: switchStyle
7
8- property real thumbPadding: units.gu(0.5)
9-
10- /* FIXME: setting the width and height is required because in the case no width
11- is set on the Switch, then even though the width is set eventually to
12- implicitWidth, it still goes through the value 0.0 which triggers an
13- undesired animation if the Switch is checked.
14-
15- Example, values of width at instantiation:
16- width = 0.0 (before SwitchStyle is loaded)
17- width = implicitWidth (after SwitchStyle is loaded)
18- */
19- width: implicitWidth
20- height: implicitHeight
21- implicitWidth: units.gu(8)
22- implicitHeight: units.gu(4)
23+ /*!
24+ The padding between the thumb and the outside border of the switch.
25+ */
26+ property real thumbPadding: units.gu(0.33)
27+
28+ /*!
29+ The padding between the icon and the border of the thumb.
30+ */
31+ property real iconPadding: thumbPadding
32+
33+ implicitWidth: units.gu(6)
34+ implicitHeight: units.gu(3)
35 opacity: styledItem.enabled ? 1.0 : 0.5
36 LayoutMirroring.enabled: false
37 LayoutMirroring.childrenInherit: true
38
39+ /*!
40+ The background color of the switch.
41+ */
42+ property color backgroundColor: Theme.palette.normal.base
43+
44+ /*!
45+ The background color of the thumb when the switch is checked.
46+ */
47+ property color checkedThumbColor: UbuntuColors.green
48+
49+ /*!
50+ The background color of the thumb when the switch is not checked.
51+ */
52+ property color uncheckedThumbColor: Qt.rgba(0, 0, 0, 0.2)
53+
54+ /*!
55+ The foreground color of the icon that is currently selected.
56+ */
57+ property color selectedIconColor: Theme.palette.normal.foregroundText
58+
59+ /*!
60+ The color of the icon that is not currently selected.
61+ */
62+ property color unselectedIconColor: Theme.palette.normal.backgroundText
63+
64+ /*!
65+ The source of the selected icon when the switch is checked.
66+ */
67+ property url checkedIconSource: "image://theme/tick"
68+
69+ /*!
70+ The source of the selected icon when the switch is not checked.
71+ */
72+ property url uncheckedIconSource: "image://theme/close"
73+
74 UbuntuShape {
75 id: background
76 anchors.fill: parent
77- color: Theme.palette.normal.base
78+ color: switchStyle.backgroundColor
79 clip: true
80
81 UbuntuShape {
82 id: thumb
83+ states: [
84+ State {
85+ name: "checked"
86+ when: styledItem.checked
87+ PropertyChanges {
88+ target: thumb
89+ x: rightThumbPosition.x
90+ color: switchStyle.checkedThumbColor
91+ }
92+ },
93+ State {
94+ name: "unchecked"
95+ when: !styledItem.checked
96+ PropertyChanges {
97+ target: thumb
98+ x: leftThumbPosition.x
99+ color: switchStyle.uncheckedThumbColor
100+ }
101+ }
102+ ]
103+
104+ transitions: [
105+ // Avoid animations on width changes (during initialization)
106+ // by explicitly setting from and to for the Transitions.
107+ Transition {
108+ from: "unchecked"
109+ to: "checked"
110+ UbuntuNumberAnimation {
111+ target: thumb
112+ properties: "x"
113+ duration: UbuntuAnimation.FastDuration
114+ easing: UbuntuAnimation.StandardEasing
115+ }
116+ ColorAnimation {
117+ target: thumb
118+ properties: "color"
119+ duration: UbuntuAnimation.FastDuration
120+ easing: UbuntuAnimation.StandardEasing
121+ }
122+ },
123+ Transition {
124+ from: "checked"
125+ to: "unchecked"
126+ UbuntuNumberAnimation {
127+ target: thumb
128+ properties: "x"
129+ duration: UbuntuAnimation.FastDuration
130+ easing: UbuntuAnimation.StandardEasing
131+ }
132+ ColorAnimation {
133+ target: thumb
134+ properties: "color"
135+ duration: UbuntuAnimation.FastDuration
136+ easing: UbuntuAnimation.StandardEasing
137+ }
138+ }
139+ ]
140
141 width: (background.width - switchStyle.thumbPadding * 3.0) / 2.0
142- x: styledItem.checked ? rightThumbPosition.x : leftThumbPosition.x
143-
144 anchors {
145 top: parent.top
146 bottom: parent.bottom
147@@ -58,31 +145,21 @@
148 bottomMargin: switchStyle.thumbPadding
149 }
150
151- color: styledItem.checked ? UbuntuColors.green
152- : Qt.rgba(0, 0, 0, 0.2)
153-
154- Behavior on x {
155- UbuntuNumberAnimation {
156- duration: UbuntuAnimation.BriskDuration
157- easing: UbuntuAnimation.StandardEasing
158- }
159- }
160- Behavior on color {
161- ColorAnimation {
162- duration: UbuntuAnimation.BriskDuration
163- easing: UbuntuAnimation.StandardEasing
164- }
165- }
166+ property real iconSize: Math.min(width, height) - 2*switchStyle.iconPadding
167
168 PartialColorize {
169 anchors {
170 verticalCenter: parent.verticalCenter
171 right: parent.left
172- rightMargin: switchStyle.thumbPadding * 3.0
173+ rightMargin: switchStyle.iconPadding + switchStyle.thumbPadding
174 }
175- rightColor: Theme.palette.normal.backgroundText
176+ rightColor: switchStyle.unselectedIconColor
177 source: Image {
178- source: "artwork/cross.png"
179+ source: switchStyle.uncheckedIconSource
180+ sourceSize {
181+ width: thumb.iconSize
182+ height: thumb.iconSize
183+ }
184 }
185 }
186
187@@ -90,11 +167,15 @@
188 anchors {
189 verticalCenter: parent.verticalCenter
190 left: parent.right
191- leftMargin: switchStyle.thumbPadding * 2.0
192+ leftMargin: switchStyle.iconPadding + switchStyle.thumbPadding
193 }
194- rightColor: Theme.palette.normal.backgroundText
195+ rightColor: switchStyle.unselectedIconColor
196 source: Image {
197- source: "artwork/tick.png"
198+ source: switchStyle.checkedIconSource
199+ sourceSize {
200+ width: thumb.iconSize
201+ height: thumb.iconSize
202+ }
203 }
204 }
205 }
206@@ -113,11 +194,15 @@
207 PartialColorize {
208 anchors.centerIn: parent
209 source: Image {
210- source: "artwork/cross.png"
211+ source: switchStyle.uncheckedIconSource
212+ sourceSize {
213+ width: thumb.iconSize
214+ height: thumb.iconSize
215+ }
216 }
217 progress: MathUtils.clamp((thumb.x - parent.x - x) / width, 0.0, 1.0)
218 leftColor: "transparent"
219- rightColor: Theme.palette.normal.foregroundText
220+ rightColor: switchStyle.selectedIconColor
221 }
222 }
223
224@@ -135,10 +220,14 @@
225 PartialColorize {
226 anchors.centerIn: parent
227 source: Image {
228- source: "artwork/tick.png"
229+ source: switchStyle.checkedIconSource
230+ sourceSize {
231+ width: thumb.iconSize
232+ height: thumb.iconSize
233+ }
234 }
235 progress: MathUtils.clamp((thumb.x + thumb.width - parent.x - x) / width, 0.0, 1.0)
236- leftColor: Theme.palette.normal.foregroundText
237+ leftColor: switchStyle.selectedIconColor
238 rightColor: "transparent"
239 }
240 }
241
242=== modified file 'modules/Ubuntu/Components/Themes/Ambiance/qmldir'
243--- modules/Ubuntu/Components/Themes/Ambiance/qmldir 2014-10-24 13:13:11 +0000
244+++ modules/Ubuntu/Components/Themes/Ambiance/qmldir 2014-11-06 21:04:28 +0000
245@@ -13,7 +13,6 @@
246 internal SelectionCursorStyle SelectionCursorStyle.qml
247 internal SheetForegroundStyle SheetForegroundStyle.qml
248 internal SliderStyle SliderStyle.qml
249-internal SwitchStyle SwitchStyle.qml
250 TabBarStyle 0.1 TabBarStyle.qml
251 TextAreaStyle 0.1 TextAreaStyle.qml
252 internal TextCursorStyle TextCursorStyle.qml
253@@ -47,6 +46,7 @@
254 PullToRefreshStyle 1.1 PullToRefreshStyle.qml
255 PageHeadStyle 1.1 PageHeadStyle.qml
256 Palette 1.1 Palette.qml
257+SwitchStyle 1.1 SwitchStyle.qml
258
259 internal TextSelectionStartCursorStyle TextSelectionStartCursorStyle.qml
260 internal TextSelectionEndCursorStyle TextSelectionEndCursorStyle.qml

Subscribers

People subscribed via source and target branches