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
=== modified file 'plugins/unityshell/src/FilterRatingsButton.cpp'
--- plugins/unityshell/src/FilterRatingsButton.cpp 2011-10-03 13:07:36 +0000
+++ plugins/unityshell/src/FilterRatingsButton.cpp 2011-10-04 11:15:20 +0000
@@ -148,9 +148,9 @@
148 }148 }
149149
150 void FilterRatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {150 void FilterRatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
151 int rating = 5;151 int rating = 0;
152 if (filter_ != NULL)152 if (filter_ != NULL && filter_->filtering)
153 rating = filter_->rating * 10;153 rating = static_cast<int>(filter_->rating * 5);
154 // FIXME: 9/26/2011154 // FIXME: 9/26/2011
155 // We should probably support an API for saying whether the ratings155 // We should probably support an API for saying whether the ratings
156 // should or shouldn't support half stars...but our only consumer at156 // should or shouldn't support half stars...but our only consumer at
@@ -158,7 +158,7 @@
158 // (Bug #839759) shouldn't. So for now just force rounding.158 // (Bug #839759) shouldn't. So for now just force rounding.
159 // int total_half_stars = rating % 2;159 // int total_half_stars = rating % 2;
160 // int total_full_stars = rating / 2;160 // int total_full_stars = rating / 2;
161 int total_full_stars = ceil (rating / 2.0);161 int total_full_stars = rating;
162 int total_half_stars = 0;162 int total_half_stars = 0;
163 163
164 nux::Geometry geometry = GetGeometry ();164 nux::Geometry geometry = GetGeometry ();
@@ -241,13 +241,14 @@
241 static void _UpdateRatingToMouse (dash::RatingsFilter::Ptr filter, int x)241 static void _UpdateRatingToMouse (dash::RatingsFilter::Ptr filter, int x)
242 {242 {
243 int width = 180;243 int width = 180;
244 float new_rating = (static_cast<float>(x) / width) + 0.10f;244 float new_rating = (static_cast<float>(x) / width);
245245
246 new_rating = ceil(10*new_rating)/10;246 // FIXME: change to 10 once we decide to support also half-stars
247 new_rating = ceil(5*new_rating)/5;
247 new_rating = new_rating > 1 ? 1 : (new_rating < 0 ? 0 : new_rating);248 new_rating = new_rating > 1 ? 1 : (new_rating < 0 ? 0 : new_rating);
248 249
249 if (filter != NULL)250 if (filter != NULL)
250 filter->rating = new_rating; 251 filter->rating = new_rating;
251 }252 }
252253
253 void FilterRatingsButton::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags) 254 void FilterRatingsButton::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
254255
=== modified file 'plugins/unityshell/src/FilterRatingsWidget.cpp'
--- plugins/unityshell/src/FilterRatingsWidget.cpp 2011-09-12 08:44:54 +0000
+++ plugins/unityshell/src/FilterRatingsWidget.cpp 2011-10-04 11:15:20 +0000
@@ -38,7 +38,8 @@
38NUX_IMPLEMENT_OBJECT_TYPE(FilterRatingsWidget);38NUX_IMPLEMENT_OBJECT_TYPE(FilterRatingsWidget);
3939
40 FilterRatingsWidget::FilterRatingsWidget (NUX_FILE_LINE_DECL)40 FilterRatingsWidget::FilterRatingsWidget (NUX_FILE_LINE_DECL)
41 : FilterExpanderLabel (_("Rating"), NUX_FILE_LINE_PARAM)41 : FilterExpanderLabel (_("Rating"), NUX_FILE_LINE_PARAM),
42 last_rating_ (0.0f)
42 {43 {
43 any_button_ = new FilterBasicButton(_("All"), NUX_TRACKER_LOCATION);44 any_button_ = new FilterBasicButton(_("All"), NUX_TRACKER_LOCATION);
44 any_button_->activated.connect(sigc::mem_fun(this, &FilterRatingsWidget::OnAnyButtonActivated));45 any_button_->activated.connect(sigc::mem_fun(this, &FilterRatingsWidget::OnAnyButtonActivated));
@@ -59,12 +60,36 @@
5960
60 void FilterRatingsWidget::OnAnyButtonActivated(nux::View *view)61 void FilterRatingsWidget::OnAnyButtonActivated(nux::View *view)
61 {62 {
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 }
63 }87 }
6488
65 void FilterRatingsWidget::SetFilter (dash::Filter::Ptr filter)89 void FilterRatingsWidget::SetFilter (dash::Filter::Ptr filter)
66 {90 {
67 filter_ = std::static_pointer_cast<dash::RatingsFilter>(filter);91 filter_ = std::static_pointer_cast<dash::RatingsFilter>(filter);
92 filter_->rating.changed.connect (sigc::mem_fun (this, &FilterRatingsWidget::OnFilterRatingChanged));
68 ratings_->SetFilter(filter);93 ratings_->SetFilter(filter);
69 SetLabel(filter_->name);94 SetLabel(filter_->name);
70 NeedRedraw();95 NeedRedraw();
7196
=== modified file 'plugins/unityshell/src/FilterRatingsWidget.h'
--- plugins/unityshell/src/FilterRatingsWidget.h 2011-09-12 03:57:01 +0000
+++ plugins/unityshell/src/FilterRatingsWidget.h 2011-10-04 11:15:20 +0000
@@ -57,7 +57,7 @@
57 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);57 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
5858
59 void OnRatingsRatingChanged(const int& new_rating);59 void OnRatingsRatingChanged(const int& new_rating);
60 void OnFilterRatingChanged(const int& new_rating);60 void OnFilterRatingChanged(float new_rating);
61 void OnAnyButtonActivated(nux::View *view);61 void OnAnyButtonActivated(nux::View *view);
6262
63 FilterBasicButton *any_button_;63 FilterBasicButton *any_button_;
@@ -65,6 +65,7 @@
65 dash::RatingsFilter::Ptr filter_;65 dash::RatingsFilter::Ptr filter_;
6666
67 private:67 private:
68 float last_rating_;
68 };69 };
6970
70}71}