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
=== modified file 'places/RatingStars.qml'
--- places/RatingStars.qml 2011-08-29 10:49:26 +0000
+++ places/RatingStars.qml 2011-09-07 13:19:27 +0000
@@ -21,7 +21,7 @@
21Item {21Item {
22 id: ratingStars22 id: ratingStars
2323
24 property real rating: 3.724 property real rating
25 property int size: 5 /* Number of stars */25 property int size: 5 /* Number of stars */
26 property alias enabled: starsMouseArea.enabled26 property alias enabled: starsMouseArea.enabled
27 property alias spacing: stars.spacing27 property alias spacing: stars.spacing
@@ -41,28 +41,11 @@
41 }41 }
4242
43 function incrementRating() {43 function incrementRating() {
44 /* Make math easier since half rating accepted */44 rating = clamp(Math.floor(rating) + 1, 1, size)
45 var double_rating = rating * 2
46
47 if ( double_rating % 1 > 0){ /* if non-integer, round up */
48 double_rating = Math.ceil(double_rating)
49 }
50 else {
51 double_rating = clamp(double_rating+1, 0, size * 2)
52 }
53 rating = double_rating / 2
54 }45 }
5546
56 function decrementRating() {47 function decrementRating() {
57 var double_rating = rating * 248 rating = clamp(Math.ceil(rating) - 1, 1, size)
58
59 if ( double_rating % 1 > 0){ /* if non-integer, round down */
60 double_rating = Math.ceil(double_rating)
61 }
62 else {
63 double_rating = clamp(double_rating-1, 0, size * 2)
64 }
65 rating = double_rating / 2
66 }49 }
6750
68 Keys.onPressed: if (handleKeyPress(event.key)) event.accepted = true51 Keys.onPressed: if (handleKeyPress(event.key)) event.accepted = true
@@ -84,7 +67,12 @@
84 Repeater {67 Repeater {
85 model: size68 model: size
86 Star {69 Star {
87 fill: clamp(rating - index, 0, 1)70 fill: if(!enabled){ /* If read-only, display any Star rating */
71 return clamp(rating - index, 0, size)
72 }
73 else{ /* If user selectable, restrict to integer selections */
74 return (rating - index > 0) ? 1 : 0
75 }
88 iconSize: starIconSize76 iconSize: starIconSize
89 selected: ( ratingStars.activeFocus )77 selected: ( ratingStars.activeFocus )
90 ratingVisible: ( ratingStars.ratingVisible )78 ratingVisible: ( ratingStars.ratingVisible )
@@ -105,19 +93,12 @@
105 property int unitWidth: starIconSize + stars.spacing93 property int unitWidth: starIconSize + stars.spacing
10694
107 function calculateRating( posX ){95 function calculateRating( posX ){
108 /* Small left-hand edge to set zero rating */
109 if( posX < 4 ) return 0
110
111 /* Mouse X coordinate over one unit, relative to that unit's left edge*/96 /* Mouse X coordinate over one unit, relative to that unit's left edge*/
112 var posXOverUnit = posX % unitWidth97 var posXOverUnit = posX % unitWidth
11398
114 /* What unit is the mouse over? This is the integer part of the rating (plus one)*/99 /* What unit is the mouse over? This is the integer part of the rating (plus one)*/
115 var rating = (posX - posXOverUnit) / unitWidth + 1100 var rating = (posX - posXOverUnit) / unitWidth + 1
116101
117 /* If posX under half the star's width, remove 0.5 from the rating */
118 if( posXOverUnit <= (starIconSize/2) ){
119 rating = rating - 0.5
120 }
121 return clamp( rating, 0, size )102 return clamp( rating, 0, size )
122 }103 }
123104

Subscribers

People subscribed via source and target branches