Merge lp:~robertcarr/unity/ratingswidget-fixdesign into lp:unity

Proposed by Robert Carr on 2011-09-26
Status: Merged
Approved by: Neil J. Patel on 2011-09-28
Approved revision: 1629
Merged at revision: 1637
Proposed branch: lp:~robertcarr/unity/ratingswidget-fixdesign
Merge into: lp:unity
Diff against target: 89 lines (+36/-9)
2 files modified
plugins/unityshell/src/FilterRatingsButton.cpp (+34/-9)
plugins/unityshell/src/FilterRatingsButton.h (+2/-0)
To merge this branch: bzr merge lp:~robertcarr/unity/ratingswidget-fixdesign
Reviewer Review Type Date Requested Status
Sam Spilsbury 2011-09-26 Pending
Review via email: mp+76983@code.launchpad.net

Description of the change

Update the filter ratings widget to fit design. Firstly the user should not be able to set half stars. Secondly the user should be able to drag and change the star rating

To post a comment you must log in.
1629. By Robert Carr on 2011-09-26

Also clamp the filter in the mouse handling so we don't filter by a fractional amount

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/FilterRatingsButton.cpp'
2--- plugins/unityshell/src/FilterRatingsButton.cpp 2011-09-15 02:09:12 +0000
3+++ plugins/unityshell/src/FilterRatingsButton.cpp 2011-09-26 14:07:29 +0000
4@@ -24,6 +24,8 @@
5 #include <Nux/Nux.h>
6 #include <NuxCore/Logger.h>
7
8+#include <math.h>
9+
10 #include "FilterRatingsButton.h"
11 #include "DashStyle.h"
12
13@@ -47,7 +49,8 @@
14 {
15 InitTheme();
16
17- mouse_down.connect (sigc::mem_fun (this, &FilterRatingsButton::RecvMouseDown) );
18+ mouse_up.connect (sigc::mem_fun (this, &FilterRatingsButton::RecvMouseUp) );
19+ mouse_drag.connect (sigc::mem_fun (this, &FilterRatingsButton::RecvMouseDrag) );
20 }
21
22 FilterRatingsButton::~FilterRatingsButton() {
23@@ -148,9 +151,16 @@
24 int rating = 5;
25 if (filter_ != NULL)
26 rating = filter_->rating * 10;
27- int total_full_stars = rating / 2;
28- int total_half_stars = rating % 2;
29-
30+ // FIXME: 9/26/2011
31+ // We should probably support an API for saying whether the ratings
32+ // should or shouldn't support half stars...but our only consumer at
33+ // the moment is the applications lens which according to design
34+ // (Bug #839759) shouldn't. So for now just force rounding.
35+ // int total_half_stars = rating % 2;
36+ // int total_full_stars = rating / 2;
37+ int total_full_stars = ceil (rating / 2.0);
38+ int total_half_stars = 0;
39+
40 nux::Geometry geometry = GetGeometry ();
41 //geometry.width = geometry.width / 5;
42 geometry.width = 27;
43@@ -227,13 +237,28 @@
44 void FilterRatingsButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
45 nux::Button::PostDraw(GfxContext, force_draw);
46 }
47-
48- void FilterRatingsButton::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags) {
49- //int width = GetGeometry().width;
50+
51+ static void _UpdateRatingToMouse (dash::RatingsFilter::Ptr filter, int x)
52+ {
53 int width = 180;
54 float new_rating = (static_cast<float>(x) / width) + 0.10f;
55- if (filter_ != NULL)
56- filter_->rating = new_rating;
57+
58+ new_rating = ceil(10*new_rating)/10;
59+
60+ if (filter != NULL)
61+ filter->rating = new_rating;
62+ }
63+
64+ void FilterRatingsButton::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
65+ {
66+ _UpdateRatingToMouse (filter_, x);
67+ }
68+
69+ void FilterRatingsButton::RecvMouseDrag (int x, int y, int dx, int dy,
70+ unsigned long button_flags,
71+ unsigned long key_flags)
72+ {
73+ _UpdateRatingToMouse (filter_, x);
74 }
75
76 void FilterRatingsButton::OnRatingsChanged (int rating) {
77
78=== modified file 'plugins/unityshell/src/FilterRatingsButton.h'
79--- plugins/unityshell/src/FilterRatingsButton.h 2011-09-06 18:30:26 +0000
80+++ plugins/unityshell/src/FilterRatingsButton.h 2011-09-26 14:07:29 +0000
81@@ -52,6 +52,8 @@
82 void InitTheme ();
83
84 void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
85+ void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
86+ void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
87 void OnRatingsChanged (int rating);
88
89 nux::CairoWrapper *prelight_empty_;