Merge lp:~mhr3/unity/bug-865482 into lp:unity

Proposed by Michal Hruby
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 1694
Proposed branch: lp:~mhr3/unity/bug-865482
Merge into: lp:unity
Diff against target: 116 lines (+37/-10)
3 files modified
plugins/unityshell/src/FilterRatingsButton.cpp (+8/-7)
plugins/unityshell/src/FilterRatingsWidget.cpp (+27/-2)
plugins/unityshell/src/FilterRatingsWidget.h (+2/-1)
To merge this branch: bzr merge lp:~mhr3/unity/bug-865482
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+78080@code.launchpad.net
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 'plugins/unityshell/src/FilterRatingsButton.cpp'
2--- plugins/unityshell/src/FilterRatingsButton.cpp 2011-10-03 13:07:36 +0000
3+++ plugins/unityshell/src/FilterRatingsButton.cpp 2011-10-04 11:15:20 +0000
4@@ -148,9 +148,9 @@
5 }
6
7 void FilterRatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
8- int rating = 5;
9- if (filter_ != NULL)
10- rating = filter_->rating * 10;
11+ int rating = 0;
12+ if (filter_ != NULL && filter_->filtering)
13+ rating = static_cast<int>(filter_->rating * 5);
14 // FIXME: 9/26/2011
15 // We should probably support an API for saying whether the ratings
16 // should or shouldn't support half stars...but our only consumer at
17@@ -158,7 +158,7 @@
18 // (Bug #839759) shouldn't. So for now just force rounding.
19 // int total_half_stars = rating % 2;
20 // int total_full_stars = rating / 2;
21- int total_full_stars = ceil (rating / 2.0);
22+ int total_full_stars = rating;
23 int total_half_stars = 0;
24
25 nux::Geometry geometry = GetGeometry ();
26@@ -241,13 +241,14 @@
27 static void _UpdateRatingToMouse (dash::RatingsFilter::Ptr filter, int x)
28 {
29 int width = 180;
30- float new_rating = (static_cast<float>(x) / width) + 0.10f;
31+ float new_rating = (static_cast<float>(x) / width);
32
33- new_rating = ceil(10*new_rating)/10;
34+ // FIXME: change to 10 once we decide to support also half-stars
35+ new_rating = ceil(5*new_rating)/5;
36 new_rating = new_rating > 1 ? 1 : (new_rating < 0 ? 0 : new_rating);
37
38 if (filter != NULL)
39- filter->rating = new_rating;
40+ filter->rating = new_rating;
41 }
42
43 void FilterRatingsButton::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
44
45=== modified file 'plugins/unityshell/src/FilterRatingsWidget.cpp'
46--- plugins/unityshell/src/FilterRatingsWidget.cpp 2011-09-12 08:44:54 +0000
47+++ plugins/unityshell/src/FilterRatingsWidget.cpp 2011-10-04 11:15:20 +0000
48@@ -38,7 +38,8 @@
49 NUX_IMPLEMENT_OBJECT_TYPE(FilterRatingsWidget);
50
51 FilterRatingsWidget::FilterRatingsWidget (NUX_FILE_LINE_DECL)
52- : FilterExpanderLabel (_("Rating"), NUX_FILE_LINE_PARAM)
53+ : FilterExpanderLabel (_("Rating"), NUX_FILE_LINE_PARAM),
54+ last_rating_ (0.0f)
55 {
56 any_button_ = new FilterBasicButton(_("All"), NUX_TRACKER_LOCATION);
57 any_button_->activated.connect(sigc::mem_fun(this, &FilterRatingsWidget::OnAnyButtonActivated));
58@@ -59,12 +60,36 @@
59
60 void FilterRatingsWidget::OnAnyButtonActivated(nux::View *view)
61 {
62- filter_->Clear();
63+ if (any_button_->active)
64+ {
65+ last_rating_ = filter_->rating;
66+ // we need to make sure the property changes, otherwise there'll be no
67+ // signals, so we'll set it to 0.0f
68+ filter_->rating = 0.0f;
69+ filter_->Clear();
70+ }
71+ else
72+ {
73+ filter_->rating = last_rating_;
74+ }
75+ }
76+
77+ void FilterRatingsWidget::OnFilterRatingChanged(float new_rating)
78+ {
79+ if (new_rating <= 0.0f)
80+ {
81+ any_button_->active = true;
82+ }
83+ else
84+ {
85+ any_button_->active = false;
86+ }
87 }
88
89 void FilterRatingsWidget::SetFilter (dash::Filter::Ptr filter)
90 {
91 filter_ = std::static_pointer_cast<dash::RatingsFilter>(filter);
92+ filter_->rating.changed.connect (sigc::mem_fun (this, &FilterRatingsWidget::OnFilterRatingChanged));
93 ratings_->SetFilter(filter);
94 SetLabel(filter_->name);
95 NeedRedraw();
96
97=== modified file 'plugins/unityshell/src/FilterRatingsWidget.h'
98--- plugins/unityshell/src/FilterRatingsWidget.h 2011-09-12 03:57:01 +0000
99+++ plugins/unityshell/src/FilterRatingsWidget.h 2011-10-04 11:15:20 +0000
100@@ -57,7 +57,7 @@
101 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
102
103 void OnRatingsRatingChanged(const int& new_rating);
104- void OnFilterRatingChanged(const int& new_rating);
105+ void OnFilterRatingChanged(float new_rating);
106 void OnAnyButtonActivated(nux::View *view);
107
108 FilterBasicButton *any_button_;
109@@ -65,6 +65,7 @@
110 dash::RatingsFilter::Ptr filter_;
111
112 private:
113+ float last_rating_;
114 };
115
116 }