Merge lp:~gerboland/unity-2d/dash-ratingstars-integer-selection-only into lp:unity-2d

Proposed by Gerry Boland
Status: Merged
Approved by: Florian Boucault
Approved revision: 701
Merged at revision: 703
Proposed branch: lp:~gerboland/unity-2d/dash-ratingstars-integer-selection-only
Merge into: lp:unity-2d
Diff against target: 76 lines (+9/-28)
1 file modified
places/RatingStars.qml (+9/-28)
To merge this branch: bzr merge lp:~gerboland/unity-2d/dash-ratingstars-integer-selection-only
Reviewer Review Type Date Requested Status
Florian Boucault Pending
Review via email: mp+74423@code.launchpad.net

Description of the change

[dash] RatingStars should only allow whole stars to be selected. See bug:839759

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'places/RatingStars.qml'
2--- places/RatingStars.qml 2011-08-29 10:49:26 +0000
3+++ places/RatingStars.qml 2011-09-07 13:19:27 +0000
4@@ -21,7 +21,7 @@
5 Item {
6 id: ratingStars
7
8- property real rating: 3.7
9+ property real rating
10 property int size: 5 /* Number of stars */
11 property alias enabled: starsMouseArea.enabled
12 property alias spacing: stars.spacing
13@@ -41,28 +41,11 @@
14 }
15
16 function incrementRating() {
17- /* Make math easier since half rating accepted */
18- var double_rating = rating * 2
19-
20- if ( double_rating % 1 > 0){ /* if non-integer, round up */
21- double_rating = Math.ceil(double_rating)
22- }
23- else {
24- double_rating = clamp(double_rating+1, 0, size * 2)
25- }
26- rating = double_rating / 2
27+ rating = clamp(Math.floor(rating) + 1, 1, size)
28 }
29
30 function decrementRating() {
31- var double_rating = rating * 2
32-
33- if ( double_rating % 1 > 0){ /* if non-integer, round down */
34- double_rating = Math.ceil(double_rating)
35- }
36- else {
37- double_rating = clamp(double_rating-1, 0, size * 2)
38- }
39- rating = double_rating / 2
40+ rating = clamp(Math.ceil(rating) - 1, 1, size)
41 }
42
43 Keys.onPressed: if (handleKeyPress(event.key)) event.accepted = true
44@@ -84,7 +67,12 @@
45 Repeater {
46 model: size
47 Star {
48- fill: clamp(rating - index, 0, 1)
49+ fill: if(!enabled){ /* If read-only, display any Star rating */
50+ return clamp(rating - index, 0, size)
51+ }
52+ else{ /* If user selectable, restrict to integer selections */
53+ return (rating - index > 0) ? 1 : 0
54+ }
55 iconSize: starIconSize
56 selected: ( ratingStars.activeFocus )
57 ratingVisible: ( ratingStars.ratingVisible )
58@@ -105,19 +93,12 @@
59 property int unitWidth: starIconSize + stars.spacing
60
61 function calculateRating( posX ){
62- /* Small left-hand edge to set zero rating */
63- if( posX < 4 ) return 0
64-
65 /* Mouse X coordinate over one unit, relative to that unit's left edge*/
66 var posXOverUnit = posX % unitWidth
67
68 /* What unit is the mouse over? This is the integer part of the rating (plus one)*/
69 var rating = (posX - posXOverUnit) / unitWidth + 1
70
71- /* If posX under half the star's width, remove 0.5 from the rating */
72- if( posXOverUnit <= (starIconSize/2) ){
73- rating = rating - 0.5
74- }
75 return clamp( rating, 0, size )
76 }
77

Subscribers

People subscribed via source and target branches