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

Proposed by Robert Carr
Status: Merged
Approved by: Neil J. Patel
Approved revision: no longer in the source branch.
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 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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/unityshell/src/FilterRatingsButton.cpp'
--- plugins/unityshell/src/FilterRatingsButton.cpp 2011-09-15 02:09:12 +0000
+++ plugins/unityshell/src/FilterRatingsButton.cpp 2011-09-26 14:07:29 +0000
@@ -24,6 +24,8 @@
24#include <Nux/Nux.h>24#include <Nux/Nux.h>
25#include <NuxCore/Logger.h>25#include <NuxCore/Logger.h>
2626
27#include <math.h>
28
27#include "FilterRatingsButton.h"29#include "FilterRatingsButton.h"
28#include "DashStyle.h"30#include "DashStyle.h"
2931
@@ -47,7 +49,8 @@
47 {49 {
48 InitTheme();50 InitTheme();
4951
50 mouse_down.connect (sigc::mem_fun (this, &FilterRatingsButton::RecvMouseDown) );52 mouse_up.connect (sigc::mem_fun (this, &FilterRatingsButton::RecvMouseUp) );
53 mouse_drag.connect (sigc::mem_fun (this, &FilterRatingsButton::RecvMouseDrag) );
51 }54 }
5255
53 FilterRatingsButton::~FilterRatingsButton() {56 FilterRatingsButton::~FilterRatingsButton() {
@@ -148,9 +151,16 @@
148 int rating = 5;151 int rating = 5;
149 if (filter_ != NULL)152 if (filter_ != NULL)
150 rating = filter_->rating * 10;153 rating = filter_->rating * 10;
151 int total_full_stars = rating / 2;154 // FIXME: 9/26/2011
152 int total_half_stars = rating % 2;155 // We should probably support an API for saying whether the ratings
153156 // should or shouldn't support half stars...but our only consumer at
157 // the moment is the applications lens which according to design
158 // (Bug #839759) shouldn't. So for now just force rounding.
159 // int total_half_stars = rating % 2;
160 // int total_full_stars = rating / 2;
161 int total_full_stars = ceil (rating / 2.0);
162 int total_half_stars = 0;
163
154 nux::Geometry geometry = GetGeometry ();164 nux::Geometry geometry = GetGeometry ();
155 //geometry.width = geometry.width / 5;165 //geometry.width = geometry.width / 5;
156 geometry.width = 27;166 geometry.width = 27;
@@ -227,13 +237,28 @@
227 void FilterRatingsButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {237 void FilterRatingsButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
228 nux::Button::PostDraw(GfxContext, force_draw);238 nux::Button::PostDraw(GfxContext, force_draw);
229 }239 }
230240
231 void FilterRatingsButton::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags) {241 static void _UpdateRatingToMouse (dash::RatingsFilter::Ptr filter, int x)
232 //int width = GetGeometry().width;242 {
233 int width = 180;243 int width = 180;
234 float new_rating = (static_cast<float>(x) / width) + 0.10f;244 float new_rating = (static_cast<float>(x) / width) + 0.10f;
235 if (filter_ != NULL)245
236 filter_->rating = new_rating;246 new_rating = ceil(10*new_rating)/10;
247
248 if (filter != NULL)
249 filter->rating = new_rating;
250 }
251
252 void FilterRatingsButton::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
253 {
254 _UpdateRatingToMouse (filter_, x);
255 }
256
257 void FilterRatingsButton::RecvMouseDrag (int x, int y, int dx, int dy,
258 unsigned long button_flags,
259 unsigned long key_flags)
260 {
261 _UpdateRatingToMouse (filter_, x);
237 }262 }
238263
239 void FilterRatingsButton::OnRatingsChanged (int rating) {264 void FilterRatingsButton::OnRatingsChanged (int rating) {
240265
=== modified file 'plugins/unityshell/src/FilterRatingsButton.h'
--- plugins/unityshell/src/FilterRatingsButton.h 2011-09-06 18:30:26 +0000
+++ plugins/unityshell/src/FilterRatingsButton.h 2011-09-26 14:07:29 +0000
@@ -52,6 +52,8 @@
52 void InitTheme ();52 void InitTheme ();
5353
54 void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);54 void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
55 void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
56 void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
55 void OnRatingsChanged (int rating);57 void OnRatingsChanged (int rating);
5658
57 nux::CairoWrapper *prelight_empty_;59 nux::CairoWrapper *prelight_empty_;