Merge lp:~azzar1/unity/filters-fixes into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Merged at revision: 1831
Proposed branch: lp:~azzar1/unity/filters-fixes
Merge into: lp:unity
Diff against target: 3803 lines (+1760/-1614)
29 files modified
UnityCore/RatingsFilter.cpp (+6/-4)
UnityCore/RatingsFilter.h (+1/-1)
manual-tests/AllButton.txt (+40/-0)
manual-tests/Filters.txt (+26/-0)
plugins/unityshell/resources/dash-widgets.json (+5/-5)
plugins/unityshell/src/FilterAllButton.cpp (+71/-0)
plugins/unityshell/src/FilterAllButton.h (+55/-0)
plugins/unityshell/src/FilterBar.cpp (+78/-67)
plugins/unityshell/src/FilterBar.h (+36/-31)
plugins/unityshell/src/FilterBasicButton.cpp (+116/-137)
plugins/unityshell/src/FilterBasicButton.h (+38/-34)
plugins/unityshell/src/FilterExpanderLabel.cpp (+124/-106)
plugins/unityshell/src/FilterExpanderLabel.h (+45/-38)
plugins/unityshell/src/FilterFactory.cpp (+44/-48)
plugins/unityshell/src/FilterFactory.h (+21/-15)
plugins/unityshell/src/FilterGenreButton.cpp (+49/-56)
plugins/unityshell/src/FilterGenreButton.h (+24/-24)
plugins/unityshell/src/FilterGenreWidget.cpp (+100/-131)
plugins/unityshell/src/FilterGenreWidget.h (+42/-44)
plugins/unityshell/src/FilterMultiRangeButton.cpp (+178/-184)
plugins/unityshell/src/FilterMultiRangeButton.h (+63/-58)
plugins/unityshell/src/FilterMultiRangeWidget.cpp (+145/-166)
plugins/unityshell/src/FilterMultiRangeWidget.h (+43/-43)
plugins/unityshell/src/FilterRatingsButton.cpp (+212/-233)
plugins/unityshell/src/FilterRatingsButton.h (+53/-51)
plugins/unityshell/src/FilterRatingsWidget.cpp (+58/-88)
plugins/unityshell/src/FilterRatingsWidget.h (+34/-41)
plugins/unityshell/src/FilterWidget.cpp (+38/-0)
plugins/unityshell/src/FilterWidget.h (+15/-9)
To merge this branch: bzr merge lp:~azzar1/unity/filters-fixes
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Michal Hruby (community) lens-integration Approve
Mirco Müller Pending
Review via email: mp+85914@code.launchpad.net

Commit message

Dash filters fixes.

Description of the change

First of all don't worry about the 3810 lines of diff because this is a update-coding-style branch too.

* Coding Style
  - Moves filters stuff in unity::dash:: namespace
  - Removes space between function name and (.
  - [Pointers] Place the asterisk adjacent to the type.
  - Adds UNITYSHELL_ prefix to each #define guard.
  - Uses nullptr

* Bug #838901

* Bug #841864
  - There is already a merge proposal [2] but it has too many conflicts so I've created my own patch with a quite different solution.
  - I've created a unity::Dash::FilterAllButton class to remove code duplication and to handle as clean as possible the "All" button design.
  - I've slightly changed UnityCore/RatingsFilter.cpp to make it working properly. Make check is ok after the change.

* Bug #841870
  - Sadly Area::SetVisible(bool) doesn't work with nux::Layout (by design and I've no idea why it is so...). So the best way to hide/unhide a nux::layout is to add/remove the layout to/from the parten layout.
  - When we remove the layout, we add a spacelayout to draw the separator line properly.

* Any other
 - I had this visual bug using unity from trunk [3]. Fixed it too.
 - I could not explain this...
      class FilterRatingsButton : public nux::Button, public unity::FilterWidget {
   Now it is:
      class FilterRatingsButton : public nux::ToggleButton {

[1] https://code.launchpad.net/~yeganeh/unity/fix-for-838901
[2] https://code.launchpad.net/~yeganeh/unity/fix-for-841864
[3] http://ubuntuone.com/7UM17vk7oa7m1paFbkKTfS

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Did you make sure this doesn't change the way the dbus signals are sent to lenses? (from looking at the changes it shouldn't though)

review: Needs Information
Revision history for this message
Andrea Azzarone (azzar1) wrote :

> Did you make sure this doesn't change the way the dbus signals are sent to
> lenses? (from looking at the changes it shouldn't though)

There's a TestRatingsFilter (or something like that) and it's ok after the changes.

The changes too UnityCore/RatingsFilter.cpp makes sure that after calling ::Clear the ratings is really setted to 0 (how happens with the other filters). The canges make sure that setting the ratings too 0 (or calling ::Clear) the filtering property is "setted" (quotation marks because it'a read only property) to false.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

*The changes to

Revision history for this message
Andrea Azzarone (azzar1) wrote :

Too many mistakes :/

> Did you make sure this doesn't change the way the dbus signals are sent to
> lenses? (from looking at the changes it shouldn't though)

There's a TestRatingsFilter (or something like that) and it's ok after the changes.

The changes to UnityCore/RatingsFilter.cpp make sure that after calling ::Clear the ratings property is really setted to 0 (how happens with the other filters). And the canges make sure that setting the ratings property to 0 (or calling ::Clear) the filtering property is "setted" (quotation marks because it'a read only property) to false.

Revision history for this message
Tim Penhey (thumper) wrote :

> - There is already a merge proposal [2] but it has too many conflicts so I've created my own patch with
> a quite different solution.

How is your solution different? Is there a good reason not to start with the existing proposal that gord had reviewed?

review: Needs Information
Revision history for this message
Andrea Azzarone (azzar1) wrote :

> > - There is already a merge proposal [2] but it has too many conflicts so
> I've created my own patch with
> > a quite different solution.
>
> How is your solution different? Is there a good reason not to start with the
> existing proposal that gord had reviewed?

It's quite similar. The existing proposal uses a base class with an all button to remove duplicate in all the *widget.cpp files. My branch uses an all button class that is added using nux layout to the widget.

P.S. There was too many conflicts. I asked him to resolve them but I didn't get an answer.

Revision history for this message
Tim Penhey (thumper) wrote :
Download full text (6.3 KiB)

Another branch that really shouldn't have mixed style changes with real changes.

Use const& params when passing objects around, even smart pointers.

  void FilterAllButton::SetFilter(Filter::Ptr const& filter)

When would this method be called?

I know that you just moved the code, but FilterBasicButton.cpp,
FilterBasicButton::ComputeContentSize, should just set the cached_geometry_
inside the if statement, and reuse "geo".

Is there a reason we aren't using the cached_geometry_ in the Draw method?
Seems weird to cache it and not use it. Gah... and GetGeometry() is called
multiple times in Draw.

+1 on adding the missing & to const std::string. Extra brownie points for
making them "std::string const&" :-)

Inside FilterExpanderLabel::SetContents, you change the behaviour slightly.
Is this ever called more than once for any given object?

By calling SinkReference you are changing it from being unowned, to just
having a reference count of 1. When it is added to the layout, it gets a
reference count of 2. Normally when the layout is destroyed, it would
dereference. This is how the old code path handled the cleanup. The
SetContents method adds the unref, but doesn't remove the old contents from
the layout. However all of this is moot if this method should only ever be
called once.

Why add a SpaceLayout that isn't added to anything?

Also, we really shouldn't be adding Reference/UnReference/SinkReference calls
anywhere. Ideally you'd use a nux::ObjectPtr<xxx> to handle this.

Hmm... things becoming clearer.

You have a bug in your removal of the space layout.
  if (space_ and space_->IsChildOf(space_))
should be
  if (space_ and space_->IsChildOf(layout_))

> layout_->AddView(space_, 1);
I hate magic numbers in code, what does the "1" do?

If you changed the space_ and contents_ members to be nux::ObjectPtr wrappers,
you wouldn't need the the UnReference/SinkReference calls.

The SetContent method could then use the Adopt method to take ownership.

/me sighs

> nux::View* FilterFactory::WidgetForFilter(Filter::Ptr filter)

Please pass the filter by const&

This code will blow up if the filter type is not understood by trying to call
a method on a dynamic_cast of a nullptr.

Firstly, don't use nux::View* for the temporary. Use a FilterWidget* and call
it, oh maybe, widget. You also don't need to static_cast up an inheritance
hierarchy, you can just assign. Also, by doing this, you don't need the
dynamic_cast either.

  FilterWidget* widget = nullptr;
  if (filter_type == renderer_type_check_options)
  {
    widget = new FilterGenre(NUX_TRACKER_LOCATION);
  }
  else if (filter_type == renderer_type_ratings)
  {
    widget = new FilterRatingsWidget(NUX_TRACKER_LOCATION);
  }
  else if (filter_type == renderer_type_multirange)
  {
    widget = new FilterMultiRange(NUX_TRACKER_LOCATION);
  }
  else if (filter_type == renderer_type_radio_options)
  {
    widget = new FilterGenre(NUX_TRACKER_LOCATION);
  }
  else
  {
    LOG_WARNING(logger) << "Do not understand filter of type \""
                        << filter_type
                        << "\"";
  }

  if (widget)
    widget->SetFilter(filter);

  return widget;

> FilterFactory.h

A...

Read more...

review: Needs Fixing
Revision history for this message
Andrea Azzarone (azzar1) wrote :
Download full text (7.5 KiB)

> Another branch that really shouldn't have mixed style changes with real
> changes.
>
> Use const& params when passing objects around, even smart pointers.
>
> void FilterAllButton::SetFilter(Filter::Ptr const& filter)

Done.

>
> When would this method be called?

Every time the associated *Widget got another filter.

>
> I know that you just moved the code, but FilterBasicButton.cpp,
> FilterBasicButton::ComputeContentSize, should just set the cached_geometry_
> inside the if statement, and reuse "geo".

Done.

>
> Is there a reason we aren't using the cached_geometry_ in the Draw method?
> Seems weird to cache it and not use it. Gah... and GetGeometry() is called
> multiple times in Draw.

We're caching cached_geometry_ to not invalidate active_ and normal_ (?) every single time.
But I think that it's legal to use cached_geometry_ in the Draw method too... Maybe we can
ask Jay.

>
> +1 on adding the missing & to const std::string. Extra brownie points for
> making them "std::string const&" :-)
>
> Inside FilterExpanderLabel::SetContents, you change the behaviour slightly.

Because SetVisible doesn't work on a nux::layout ;)

> Is this ever called more than once for any given object?

It should be called just the first time.

>
> By calling SinkReference you are changing it from being unowned, to just
> having a reference count of 1. When it is added to the layout, it gets a
> reference count of 2. Normally when the layout is destroyed, it would
> dereference. This is how the old code path handled the cleanup. The
> SetContents method adds the unref, but doesn't remove the old contents from
> the layout. However all of this is moot if this method should only ever be
> called once.
>
> Why add a SpaceLayout that isn't added to anything?

It was necessary to add an extra padding during the collapse state. I've found a
cleaner solution ;)

>
> Also, we really shouldn't be adding Reference/UnReference/SinkReference calls
> anywhere. Ideally you'd use a nux::ObjectPtr<xxx> to handle this.

Done ;)

>
> Hmm... things becoming clearer.
>
> You have a bug in your removal of the space layout.
> if (space_ and space_->IsChildOf(space_))
> should be
> if (space_ and space_->IsChildOf(layout_))
>
> > layout_->AddView(space_, 1);
> I hate magic numbers in code, what does the "1" do?
>

No longer needed. I've just removed space_;

> If you changed the space_ and contents_ members to be nux::ObjectPtr wrappers,
> you wouldn't need the the UnReference/SinkReference calls.
>
> The SetContent method could then use the Adopt method to take ownership.

Done.

>
> /me sighs
>
> > nux::View* FilterFactory::WidgetForFilter(Filter::Ptr filter)
>
> Please pass the filter by const&

Done.

>
> This code will blow up if the filter type is not understood by trying to call
> a method on a dynamic_cast of a nullptr.

Done.

>
> Firstly, don't use nux::View* for the temporary. Use a FilterWidget* and call
> it, oh maybe, widget. You also don't need to static_cast up an inheritance
> hierarchy, you can just assign. Also, by doing this, you don't need the
> dynamic_cast either.
>
> FilterWidget* widget = nullptr;
> if (filter_typ...

Read more...

Revision history for this message
Tim Penhey (thumper) wrote :

The only change is to make the FilterWidget inherit from nux::View, then the FilterExpanderLabel inherits from FilterWidget. This will remove the multiple inheritance, and the need for the dynamic_cast in the factory method.

review: Needs Fixing
Revision history for this message
Andrea Azzarone (azzar1) wrote :

> The only change is to make the FilterWidget inherit from nux::View, then the
> FilterExpanderLabel inherits from FilterWidget. This will remove the multiple
> inheritance, and the need for the dynamic_cast in the factory method.

Done.

Revision history for this message
Michal Hruby (mhr3) wrote :

Works well with latest libunity.

review: Approve (lens-integration)
Revision history for this message
Tim Penhey (thumper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/RatingsFilter.cpp'
2--- UnityCore/RatingsFilter.cpp 2011-08-05 16:06:01 +0000
3+++ UnityCore/RatingsFilter.cpp 2012-01-11 09:37:33 +0000
4@@ -41,7 +41,7 @@
5
6 void RatingsFilter::Clear()
7 {
8- UpdateState(0.0f, false);
9+ rating = 0.0f;
10 }
11
12 void RatingsFilter::Update(Filter::Hints& hints)
13@@ -61,13 +61,15 @@
14
15 void RatingsFilter::OnRatingChanged(float new_value)
16 {
17- UpdateState(new_value, true);
18+ UpdateState(new_value);
19 }
20
21-void RatingsFilter::UpdateState(float raw_rating, bool raw_filtering)
22+void RatingsFilter::UpdateState(float raw_rating)
23 {
24 if (!IsValid())
25 return;
26+
27+ bool new_filtering = raw_rating > 0.0f;
28
29 GVariantBuilder b;
30 g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
31@@ -79,7 +81,7 @@
32 g_variant_builder_end(&b));
33 dee_model_set_value(model_, iter_,
34 FilterColumn::FILTERING,
35- g_variant_new("b", raw_filtering ? TRUE : FALSE));
36+ g_variant_new("b", new_filtering ? TRUE : FALSE));
37 IgnoreChanges(false);
38
39 filtering.EmitChanged(filtering);
40
41=== modified file 'UnityCore/RatingsFilter.h'
42--- UnityCore/RatingsFilter.h 2011-07-28 20:56:33 +0000
43+++ UnityCore/RatingsFilter.h 2012-01-11 09:37:33 +0000
44@@ -43,7 +43,7 @@
45
46 private:
47 void OnRatingChanged(float new_value);
48- void UpdateState(float rating, bool filtering);
49+ void UpdateState(float new_rating);
50 };
51
52 }
53
54=== added file 'manual-tests/AllButton.txt'
55--- manual-tests/AllButton.txt 1970-01-01 00:00:00 +0000
56+++ manual-tests/AllButton.txt 2012-01-11 09:37:33 +0000
57@@ -0,0 +1,40 @@
58+Test Filter "All" Button
59+========================
60+These tests show that the dash "All" button works well.
61+
62+
63+Test "All" Button 1
64+-------------------
65+
66+#. Just after the login open the "Filter results".
67+
68+Outcome
69+ "All" should be selected by default in every filter category.
70+
71+Test "All" Button 2
72+-------------------
73+
74+#. Make sure the "All" button is selected.
75+#. Try to activate it.
76+
77+Outcome
78+ Click on it should do nothing.
79+
80+
81+Test "All" Button 3
82+-------------------
83+
84+#. Make sure the "All" button is selected.
85+#. Select another item in the filter category.
86+
87+Outcome:
88+ The all button should automatically toggle to the un-selected state.
89+
90+Test "All" Button 4
91+-------------------
92+
93+#. Make sure the one or more items is selected in a filter category.
94+#. Deselect all items.
95+
96+Outcome:
97+ The all button should automatically toggle to the selected state.
98
99=== added file 'manual-tests/Filters.txt'
100--- manual-tests/Filters.txt 1970-01-01 00:00:00 +0000
101+++ manual-tests/Filters.txt 2012-01-11 09:37:33 +0000
102@@ -0,0 +1,26 @@
103+Test Expand/Collapse Filters
104+========================
105+This test shows that the expand/collapse arrow of a filter category
106+header works well.
107+
108+#. Open the dash.
109+#. Make sure that a collapse arrow is shown adjacent to every
110+ filter category header.
111+#. Click on it.
112+#. The filter category should collapse.
113+#. Make sure that an expand arrow is shown ajacent to every filter
114+ category header.
115+#. Click on it (again).
116+#. The filter category should expand.
117+
118+
119+Test no-over-state effect
120+=========================
121+This test show that filter buttons in the Dash do not have a mouse
122+over state.
123+
124+#. Open the dash.
125+#. Move the mouse on filter buttons.
126+
127+Outcome
128+ The filter buttons have no mouseover state effect.
129
130=== modified file 'plugins/unityshell/resources/dash-widgets.json'
131--- plugins/unityshell/resources/dash-widgets.json 2011-10-10 16:45:13 +0000
132+++ plugins/unityshell/resources/dash-widgets.json 2012-01-11 09:37:33 +0000
133@@ -23,9 +23,9 @@
134
135 "button-icon": {
136 "color" : ["#ffffff", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF"],
137- "opacity" : [ 1.0, 1.0, 0.8, 0.8, 0.8],
138- "overlay-opacity": [ 0.30, 0.48, 0.45, 0.45, 0.45],
139- "overlay-mode" : [ "normal","multiply", "normal", "normal", "normal"],
140+ "opacity" : [ 1.0, 1.0, 1.0, 0.8, 0.8],
141+ "overlay-opacity": [ 0.30, 0.48, 0.48, 0.45, 0.45],
142+ "overlay-mode" : [ "normal","multiply", "multiply", "normal", "normal"],
143 "blur-size" : [ 5, 0, 0, 0, 0]},
144
145 "icon-only" : {
146@@ -46,8 +46,8 @@
147 "text-size" : 1.0,
148 "text-color" : ["#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff"],
149 "text-opacity" : [ 1.0, 1.0, 1.0, 1.0, 1.0],
150- "fill-color" : ["#FFFFFF", "#000000", "#ffffff", "#000000", "#000000"],
151- "fill-opacity" : [ 0.25, 0.0, 0.25, 0.0, 0.0],
152+ "fill-color" : ["#FFFFFF", "#000000", "#000000", "#000000", "#000000"],
153+ "fill-opacity" : [ 0.25, 0.0, 0.0, 0.0, 0.0],
154 "overlay-opacity": [ 0.1, 0.1, 0.1, 0.0, 0.0],
155 "overlay-mode" : [ "normal", "normal", "normal", "normal", "normal"],
156 "blur-size" : [ 1, 1, 1, 0, 0]},
157
158=== added file 'plugins/unityshell/src/FilterAllButton.cpp'
159--- plugins/unityshell/src/FilterAllButton.cpp 1970-01-01 00:00:00 +0000
160+++ plugins/unityshell/src/FilterAllButton.cpp 2012-01-11 09:37:33 +0000
161@@ -0,0 +1,71 @@
162+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
163+/*
164+ * Copyright 2011 Canonical Ltd.
165+ *
166+ * This program is free software: you can redistribute it and/or modify it
167+ * under the terms of the GNU Lesser General Public License version 3, as
168+ * published by the Free Software Foundation.
169+ *
170+ * This program is distributed in the hope that it will be useful, but
171+ * WITHOUT ANY WARRANTY; without even the implied warranties of
172+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
173+ * PURPOSE. See the applicable version of the GNU Lesser General Public
174+ * License for more details.
175+ *
176+ * You should have received a copy of both the GNU Lesser General Public
177+ * License version 3 along with this program. If not, see
178+ * <http://www.gnu.org/licenses/>
179+ *
180+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
181+ *
182+ */
183+
184+
185+#include <glib.h>
186+#include <glib/gi18n-lib.h>
187+
188+#include "FilterAllButton.h"
189+
190+namespace unity
191+{
192+namespace dash
193+{
194+
195+FilterAllButton::FilterAllButton(NUX_FILE_LINE_DECL)
196+ : FilterBasicButton(_("All"), NUX_FILE_LINE_PARAM)
197+{
198+ SetActive(true);
199+ SetInputEventSensitivity(false);
200+
201+ state_change.connect(sigc::mem_fun(this, &FilterAllButton::OnStateChanged));
202+}
203+
204+FilterAllButton::~FilterAllButton()
205+{
206+}
207+
208+void FilterAllButton::SetFilter(Filter::Ptr const& filter)
209+{
210+ if (filtering_connection_.connected())
211+ filtering_connection_.disconnect();
212+
213+ filter_ = filter;
214+ OnFilteringChanged(filter_->filtering); // Evil hack ;)
215+
216+ filtering_connection_ = filter_->filtering.changed.connect(sigc::mem_fun(this, &FilterAllButton::OnFilteringChanged));
217+}
218+
219+void FilterAllButton::OnStateChanged(nux::View* view)
220+{
221+ if (filter_ and Active())
222+ filter_->Clear();
223+}
224+
225+void FilterAllButton::OnFilteringChanged(bool filtering)
226+{
227+ SetActive(!filtering);
228+ SetInputEventSensitivity(filtering);
229+}
230+
231+} // namespace dash
232+} // namespace unity
233
234=== added file 'plugins/unityshell/src/FilterAllButton.h'
235--- plugins/unityshell/src/FilterAllButton.h 1970-01-01 00:00:00 +0000
236+++ plugins/unityshell/src/FilterAllButton.h 2012-01-11 09:37:33 +0000
237@@ -0,0 +1,55 @@
238+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
239+/*
240+ * Copyright 2011 Canonical Ltd.
241+ *
242+ * This program is free software: you can redistribute it and/or modify it
243+ * under the terms of the GNU Lesser General Public License version 3, as
244+ * published by the Free Software Foundation.
245+ *
246+ * This program is distributed in the hope that it will be useful, but
247+ * WITHOUT ANY WARRANTY; without even the implied warranties of
248+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
249+ * PURPOSE. See the applicable version of the GNU Lesser General Public
250+ * License for more details.
251+ *
252+ * You should have received a copy of both the GNU Lesser General Public
253+ * License version 3 along with this program. If not, see
254+ * <http://www.gnu.org/licenses/>
255+ *
256+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
257+ *
258+ */
259+
260+#ifndef UNITYSHELL_FILTERALLBUTTON_H
261+#define UNITYSHELL_FILTERALLBUTTON_H
262+
263+#include <sigc++/connection.h>
264+
265+#include "FilterBasicButton.h"
266+
267+namespace unity
268+{
269+namespace dash
270+{
271+
272+class FilterAllButton : public FilterBasicButton
273+{
274+public:
275+ FilterAllButton(NUX_FILE_LINE_PROTO);
276+ ~FilterAllButton();
277+
278+ void SetFilter(Filter::Ptr const& filter);
279+
280+private:
281+ void OnFilteringChanged(bool filtering);
282+ void OnStateChanged(nux::View* view);
283+
284+ Filter::Ptr filter_;
285+ sigc::connection filtering_connection_;
286+};
287+
288+} // namespace dash
289+} // namespace unity
290+
291+#endif // UNITYSHELL_FILTERALLBUTTON_H
292+
293
294=== modified file 'plugins/unityshell/src/FilterBar.cpp'
295--- plugins/unityshell/src/FilterBar.cpp 2011-10-19 16:28:06 +0000
296+++ plugins/unityshell/src/FilterBar.cpp 2012-01-11 09:37:33 +0000
297@@ -21,83 +21,94 @@
298
299 #include <Nux/Nux.h>
300 #include <Nux/VLayout.h>
301+#include <NuxCore/Logger.h>
302
303 #include "FilterBar.h"
304 #include "FilterFactory.h"
305
306 namespace unity
307 {
308+namespace dash
309+{
310+namespace
311+{
312+
313+nux::logging::Logger logger("unity.dash.filterbar");
314+
315+}
316
317 NUX_IMPLEMENT_OBJECT_TYPE(FilterBar);
318
319- FilterBar::FilterBar(NUX_FILE_LINE_DECL)
320- : View (NUX_FILE_LINE_PARAM) {
321- // TODO - does the filterbar associate itself with a model of some sort?
322- // does libunity provide a Lens.Filters model or something that we can update on?
323- // don't want to associate a Filterbar with just a lens model, its a filter bar not a
324- // lens parser
325- Init ();
326- }
327-
328- FilterBar::~FilterBar()
329- {
330- }
331-
332- void FilterBar::Init () {
333- nux::LinearLayout *layout = new nux::VLayout (NUX_TRACKER_LOCATION);
334- layout->SetSpaceBetweenChildren(12);
335- SetLayout (layout);
336- }
337-
338- void FilterBar::SetFilters (dash::Filters::Ptr filters)
339- {
340- filters_ = filters;
341- }
342-
343- void FilterBar::AddFilter (dash::Filter::Ptr filter) {
344- if (filter_map_.count (filter) > 0) {
345- g_warning ("Attempting to add a filter that has already been added");
346- return;
347- }
348-
349- nux::View *filter_view = factory_.WidgetForFilter (filter);
350- filter_map_[filter] = filter_view;
351- GetLayout()->AddView(filter_view, 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
352- }
353-
354- void FilterBar::RemoveFilter (dash::Filter::Ptr filter) {
355- for (auto iter: filter_map_)
356+FilterBar::FilterBar(NUX_FILE_LINE_DECL)
357+ : View(NUX_FILE_LINE_PARAM)
358+{
359+ // TODO - does the filterbar associate itself with a model of some sort?
360+ // does libunity provide a Lens.Filters model or something that we can update on?
361+ // don't want to associate a Filterbar with just a lens model, its a filter bar not a
362+ // lens parser
363+ Init();
364+}
365+
366+FilterBar::~FilterBar()
367+{
368+}
369+
370+void FilterBar::Init()
371+{
372+ nux::LinearLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION);
373+ layout->SetSpaceBetweenChildren(12);
374+ SetLayout(layout);
375+}
376+
377+void FilterBar::SetFilters(Filters::Ptr const& filters)
378+{
379+ filters_ = filters;
380+}
381+
382+void FilterBar::AddFilter(Filter::Ptr const& filter)
383+{
384+ if (filter_map_.count(filter) > 0)
385+ {
386+ LOG_WARN(logger) << "Attempting to add a filter that has already been added";
387+ return;
388+ }
389+
390+ nux::View* filter_view = factory_.WidgetForFilter(filter);
391+ filter_map_[filter] = filter_view;
392+ GetLayout()->AddView(filter_view, 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
393+}
394+
395+void FilterBar::RemoveFilter(Filter::Ptr const& filter)
396+{
397+ for (auto iter: filter_map_)
398+ {
399+ if (iter.first->id == filter->id)
400 {
401- if (iter.first->id == filter->id)
402- {
403- nux::View *filter_view = iter.second;
404- filter_map_.erase (filter_map_.find(iter.first));
405- GetLayout()->RemoveChildObject(filter_view);
406- break;
407- }
408+ nux::View* filter_view = iter.second;
409+ filter_map_.erase(filter_map_.find(iter.first));
410+ GetLayout()->RemoveChildObject(filter_view);
411+ break;
412 }
413 }
414-
415- void FilterBar::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
416- nux::Geometry geo = GetGeometry();
417-
418- GfxContext.PushClippingRectangle(geo);
419- nux::GetPainter().PaintBackground(GfxContext, geo);
420- GfxContext.PopClippingRectangle();
421- }
422-
423- void FilterBar::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
424- GfxContext.PushClippingRectangle(GetGeometry());
425-
426- GetLayout()->ProcessDraw(GfxContext, force_draw);
427-
428- GfxContext.PopClippingRectangle();
429- }
430-
431- void FilterBar::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
432- nux::View::PostDraw(GfxContext, force_draw);
433- }
434-
435-
436-}
437+}
438+
439+void FilterBar::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
440+{
441+ nux::Geometry const& geo = GetGeometry();
442+
443+ GfxContext.PushClippingRectangle(geo);
444+ nux::GetPainter().PaintBackground(GfxContext, geo);
445+ GfxContext.PopClippingRectangle();
446+}
447+
448+void FilterBar::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
449+{
450+ GfxContext.PushClippingRectangle(GetGeometry());
451+ GetLayout()->ProcessDraw(GfxContext, force_draw);
452+ GfxContext.PopClippingRectangle();
453+}
454+
455+
456+} // namespace dash
457+} // namespace unity
458
459
460=== modified file 'plugins/unityshell/src/FilterBar.h'
461--- plugins/unityshell/src/FilterBar.h 2011-10-11 18:18:13 +0000
462+++ plugins/unityshell/src/FilterBar.h 2012-01-11 09:37:33 +0000
463@@ -20,8 +20,8 @@
464 *
465 */
466
467-#ifndef FILTERBAR_H
468-#define FILTERBAR_H
469+#ifndef UNITYSHELL_FILTERBAR_H
470+#define UNITYSHELL_FILTERBAR_H
471
472 #include <Nux/View.h>
473
474@@ -29,32 +29,37 @@
475
476 #include "FilterFactory.h"
477
478-namespace unity {
479-
480- class FilterBar : public nux::View
481- {
482- NUX_DECLARE_OBJECT_TYPE(FilterBar, nux::View);
483- public:
484- FilterBar(NUX_FILE_LINE_PROTO);
485- ~FilterBar();
486-
487- void SetFilters (dash::Filters::Ptr filters);
488-
489- void AddFilter (dash::Filter::Ptr filter);
490- void RemoveFilter (dash::Filter::Ptr filter);
491-
492- protected:
493- virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
494- virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
495- virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
496-
497- private:
498- void Init ();
499-
500- FilterFactory factory_;
501- dash::Filters::Ptr filters_;
502- std::map <dash::Filter::Ptr, nux::View *> filter_map_;
503- };
504-}
505-
506-#endif // FILTERBAR_H
507+namespace unity
508+{
509+namespace dash
510+{
511+
512+class FilterBar : public nux::View
513+{
514+ NUX_DECLARE_OBJECT_TYPE(FilterBar, nux::View);
515+public:
516+ FilterBar(NUX_FILE_LINE_PROTO);
517+ ~FilterBar();
518+
519+ void SetFilters(Filters::Ptr const& filters);
520+
521+ void AddFilter(Filter::Ptr const& filter);
522+ void RemoveFilter(Filter::Ptr const& filter);
523+
524+protected:
525+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
526+ virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
527+
528+private:
529+ void Init();
530+
531+ FilterFactory factory_;
532+ Filters::Ptr filters_;
533+ std::map<Filter::Ptr, nux::View*> filter_map_;
534+};
535+
536+} // namespace dash
537+} // namespace unity
538+
539+#endif // UNITYSHELL_FILTERBAR_H
540+
541
542=== modified file 'plugins/unityshell/src/FilterBasicButton.cpp'
543--- plugins/unityshell/src/FilterBasicButton.cpp 2011-11-08 19:41:00 +0000
544+++ plugins/unityshell/src/FilterBasicButton.cpp 2012-01-11 09:37:33 +0000
545@@ -18,144 +18,123 @@
546 * Authored by: Gordon Allott <gord.allott@canonical.com>
547 *
548 */
549-#include "config.h"
550-
551-#include <Nux/Nux.h>
552-#include <NuxCore/Logger.h>
553
554 #include "DashStyle.h"
555 #include "FilterBasicButton.h"
556
557-namespace
558-{
559-nux::logging::Logger logger("unity.dash.FilterBasicButton");
560-}
561-
562-namespace unity {
563-
564- FilterBasicButton::FilterBasicButton (nux::TextureArea *image, NUX_FILE_LINE_DECL)
565- : nux::ToggleButton (image, NUX_FILE_LINE_PARAM)
566- , prelight_ (NULL)
567- , active_ (NULL)
568- , normal_ (NULL)
569- {
570- InitTheme();
571- }
572-
573- FilterBasicButton::FilterBasicButton (const std::string label, NUX_FILE_LINE_DECL)
574- : nux::ToggleButton (NUX_FILE_LINE_PARAM)
575- , prelight_ (NULL)
576- , active_ (NULL)
577- , normal_ (NULL)
578- , label_ (label)
579- {
580- InitTheme();
581- }
582-
583- FilterBasicButton::FilterBasicButton (const std::string label, nux::TextureArea *image, NUX_FILE_LINE_DECL)
584- : nux::ToggleButton (image, NUX_FILE_LINE_PARAM)
585- , prelight_ (NULL)
586- , active_ (NULL)
587- , normal_ (NULL)
588- , label_ (label)
589- {
590- InitTheme();
591- }
592-
593- FilterBasicButton::FilterBasicButton (NUX_FILE_LINE_DECL)
594- : nux::ToggleButton (NUX_FILE_LINE_PARAM)
595- , prelight_ (NULL)
596- , active_ (NULL)
597- , normal_ (NULL)
598- {
599- InitTheme();
600- }
601-
602- FilterBasicButton::~FilterBasicButton() {
603- delete prelight_;
604- delete active_;
605- delete normal_;
606-
607- }
608-
609- void FilterBasicButton::InitTheme()
610- {
611- if (prelight_ == NULL)
612- {
613- prelight_ = new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT));
614- active_ = new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED));
615- normal_ = new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL));
616- }
617-
618- // SetMinimumHeight(32);
619- }
620-
621- void FilterBasicButton::RedrawTheme (nux::Geometry const& geom, cairo_t *cr, nux::ButtonVisualState faked_state)
622- {
623- dash::Style::Instance().Button(cr, faked_state, label_);
624- }
625-
626- long FilterBasicButton::ComputeContentSize ()
627- {
628- long ret = nux::Button::ComputeContentSize();
629- if (cached_geometry_ != GetGeometry())
630- {
631- nux::Geometry geo = GetGeometry();
632- prelight_->Invalidate(geo);
633- active_->Invalidate(geo);
634- normal_->Invalidate(geo);
635- }
636-
637- cached_geometry_ = GetGeometry();
638- return ret;
639- }
640-
641- void FilterBasicButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
642- gPainter.PaintBackground(GfxContext, GetGeometry());
643- // set up our texture mode
644- nux::TexCoordXForm texxform;
645- texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
646- texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
647-
648- // clear what is behind us
649- unsigned int alpha = 0, src = 0, dest = 0;
650- GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
651- GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
652-
653- nux::Color col = nux::color::Black;
654- col.alpha = 0;
655- GfxContext.QRP_Color(GetGeometry().x,
656- GetGeometry().y,
657- GetGeometry().width,
658- GetGeometry().height,
659- col);
660-
661- nux::BaseTexture *texture = normal_->GetTexture();
662- if (Active())
663- texture = active_->GetTexture();
664- else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
665- texture = prelight_->GetTexture();
666- else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
667- {
668- texture = active_->GetTexture();
669- }
670-
671- GfxContext.QRP_1Tex(GetGeometry().x,
672- GetGeometry().y,
673- GetGeometry().width,
674- GetGeometry().height,
675- texture->GetDeviceTexture(),
676- texxform,
677- nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
678-
679- GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
680- }
681-
682- void FilterBasicButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
683- }
684-
685- void FilterBasicButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
686- nux::Button::PostDraw(GfxContext, force_draw);
687- }
688-
689-}
690+namespace unity
691+{
692+namespace dash
693+{
694+
695+FilterBasicButton::FilterBasicButton(nux::TextureArea* image, NUX_FILE_LINE_DECL)
696+ : nux::ToggleButton(image, NUX_FILE_LINE_PARAM)
697+{
698+ InitTheme();
699+}
700+
701+FilterBasicButton::FilterBasicButton(std::string const& label, NUX_FILE_LINE_DECL)
702+ : nux::ToggleButton(NUX_FILE_LINE_PARAM)
703+ , label_(label)
704+{
705+ InitTheme();
706+}
707+
708+FilterBasicButton::FilterBasicButton(std::string const& label, nux::TextureArea* image, NUX_FILE_LINE_DECL)
709+ : nux::ToggleButton(image, NUX_FILE_LINE_PARAM)
710+ , label_(label)
711+{
712+ InitTheme();
713+}
714+
715+FilterBasicButton::FilterBasicButton(NUX_FILE_LINE_DECL)
716+ : nux::ToggleButton(NUX_FILE_LINE_PARAM)
717+{
718+ InitTheme();
719+}
720+
721+FilterBasicButton::~FilterBasicButton()
722+{
723+}
724+
725+void FilterBasicButton::InitTheme()
726+{
727+ if (!active_)
728+ {
729+ nux::Geometry const& geo = GetGeometry();
730+
731+ prelight_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
732+ active_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED)));
733+ normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
734+ }
735+
736+ // SetMinimumHeight(32);
737+}
738+
739+void FilterBasicButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state)
740+{
741+ Style::Instance().Button(cr, faked_state, label_);
742+}
743+
744+long FilterBasicButton::ComputeContentSize()
745+{
746+ long ret = nux::Button::ComputeContentSize();
747+ nux::Geometry const& geo = GetGeometry();
748+
749+ if (cached_geometry_ != geo)
750+ {
751+ prelight_->Invalidate(geo);
752+ active_->Invalidate(geo);
753+ normal_->Invalidate(geo);
754+
755+ cached_geometry_ = geo;
756+ }
757+
758+ return ret;
759+}
760+
761+void FilterBasicButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
762+{
763+ nux::Geometry const& geo = GetGeometry();
764+
765+ gPainter.PaintBackground(GfxContext, geo);
766+ // set up our texture mode
767+ nux::TexCoordXForm texxform;
768+ texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
769+ texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
770+
771+ // clear what is behind us
772+ unsigned int alpha = 0, src = 0, dest = 0;
773+ GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
774+ GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
775+
776+ nux::Color col = nux::color::Black;
777+ col.alpha = 0;
778+ GfxContext.QRP_Color(geo.x,
779+ geo.y,
780+ geo.width,
781+ geo.height,
782+ col);
783+
784+ nux::BaseTexture* texture = normal_->GetTexture();
785+ if (Active())
786+ texture = active_->GetTexture();
787+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
788+ texture = prelight_->GetTexture();
789+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
790+ texture = active_->GetTexture();
791+
792+ GfxContext.QRP_1Tex(geo.x,
793+ geo.y,
794+ geo.width,
795+ geo.height,
796+ texture->GetDeviceTexture(),
797+ texxform,
798+ nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
799+
800+ GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
801+}
802+
803+} // namespace dash
804+} // namespace unity
805+
806
807=== modified file 'plugins/unityshell/src/FilterBasicButton.h'
808--- plugins/unityshell/src/FilterBasicButton.h 2011-10-25 16:21:21 +0000
809+++ plugins/unityshell/src/FilterBasicButton.h 2012-01-11 09:37:33 +0000
810@@ -19,10 +19,8 @@
811 *
812 */
813
814-
815-
816-#ifndef FILTERBASICBUTTON_H
817-#define FILTERBASICBUTTON_H
818+#ifndef UNITYSHELL_FILTERBASICBUTTON_H
819+#define UNITYSHELL_FILTERBASICBUTTON_H
820
821 #include <Nux/Nux.h>
822 #include <Nux/CairoWrapper.h>
823@@ -30,33 +28,39 @@
824
825 #include "FilterWidget.h"
826
827-namespace unity {
828-
829- class FilterBasicButton : public nux::ToggleButton {
830- public:
831- FilterBasicButton (nux::TextureArea *image, NUX_FILE_LINE_PROTO);
832- FilterBasicButton (const std::string label, NUX_FILE_LINE_PROTO);
833- FilterBasicButton (const std::string label, nux::TextureArea *image, NUX_FILE_LINE_PROTO);
834- FilterBasicButton (NUX_FILE_LINE_PROTO);
835- virtual ~FilterBasicButton();
836-
837- protected:
838- virtual long ComputeContentSize();
839- virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
840- virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
841- virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
842-
843- void InitTheme ();
844- void RedrawTheme (nux::Geometry const& geom, cairo_t *cr, nux::ButtonVisualState faked_state);
845-
846- nux::CairoWrapper *prelight_;
847- nux::CairoWrapper *active_;
848- nux::CairoWrapper *normal_;
849- nux::Geometry cached_geometry_;
850-
851- private:
852- std::string label_;
853- };
854-
855-}
856-#endif // FILTERBASICBUTTON_H
857+namespace unity
858+{
859+namespace dash
860+{
861+
862+class FilterBasicButton : public nux::ToggleButton
863+{
864+public:
865+ FilterBasicButton(nux::TextureArea* image, NUX_FILE_LINE_PROTO);
866+ FilterBasicButton(std::string const& label, NUX_FILE_LINE_PROTO);
867+ FilterBasicButton(std::string const& label, nux::TextureArea* image, NUX_FILE_LINE_PROTO);
868+ FilterBasicButton(NUX_FILE_LINE_PROTO);
869+ virtual ~FilterBasicButton();
870+
871+protected:
872+ virtual long ComputeContentSize();
873+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
874+
875+ void InitTheme();
876+ void RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state);
877+
878+ typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr;
879+
880+ NuxCairoPtr prelight_;
881+ NuxCairoPtr active_;
882+ NuxCairoPtr normal_;
883+ nux::Geometry cached_geometry_;
884+
885+private:
886+ std::string label_;
887+};
888+
889+} // namespace dash
890+} // namespace unity
891+
892+#endif // UNITYSHELL_FILTERBASICBUTTON_H
893
894=== modified file 'plugins/unityshell/src/FilterExpanderLabel.cpp'
895--- plugins/unityshell/src/FilterExpanderLabel.cpp 2011-10-25 19:37:13 +0000
896+++ plugins/unityshell/src/FilterExpanderLabel.cpp 2012-01-11 09:37:33 +0000
897@@ -20,115 +20,133 @@
898 *
899 */
900
901-#include "config.h"
902-
903-#include <Nux/Nux.h>
904-
905+#include "DashStyle.h"
906 #include "FilterBasicButton.h"
907 #include "FilterExpanderLabel.h"
908-#include "DashStyle.h"
909
910-namespace unity {
911+namespace unity
912+{
913+namespace dash
914+{
915
916 NUX_IMPLEMENT_OBJECT_TYPE(FilterExpanderLabel);
917
918- FilterExpanderLabel::FilterExpanderLabel (std::string label, NUX_FILE_LINE_DECL)
919- : nux::View (NUX_FILE_LINE_PARAM)
920- , expanded (true)
921- , top_bar_layout_ (NULL)
922- , contents_ (NULL)
923- , right_hand_contents_ (NULL)
924- , expander_graphic_ (NULL)
925- , label_("<span size='larger' weight='bold'>" + label + "</span>")
926- {
927- expanded.changed.connect (sigc::mem_fun(this, &FilterExpanderLabel::DoExpandChange));
928- BuildLayout ();
929- }
930-
931- FilterExpanderLabel::~FilterExpanderLabel() {
932-
933- }
934-
935- void FilterExpanderLabel::SetLabel (std::string label)
936- {
937- label_ = "<span size='larger' weight='bold'>" + label + "</span>";
938- cairo_label_->SetText(label_.c_str());
939- }
940-
941- void FilterExpanderLabel::SetRightHandView (nux::View *view)
942- {
943- view->SetMaximumHeight(30);
944-
945- right_hand_contents_ = view;
946- top_bar_layout_->AddView(right_hand_contents_, 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
947- }
948-
949- void FilterExpanderLabel::SetContents (nux::Layout *contents)
950- {
951- contents_ = contents;
952- contents_->SetVisible(expanded);
953- layout_->AddLayout (contents_, 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
954-
955- QueueDraw();
956- }
957-
958- void FilterExpanderLabel::BuildLayout ()
959- {
960- layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
961- top_bar_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
962-
963- cairo_label_ = new nux::StaticText(label_.c_str(), NUX_TRACKER_LOCATION);
964- cairo_label_->SetFontName("Ubuntu 10");
965- cairo_label_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
966- cairo_label_->mouse_down.connect(
967- [&](int x, int y, unsigned long button_flags, unsigned long key_flag)
968- {
969- expanded = !expanded;
970- if (contents_)
971- contents_->SetVisible(expanded);
972- QueueDraw();
973- });
974-
975- top_bar_layout_->AddView (cairo_label_, 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
976- top_bar_layout_->AddSpace(1, 1);
977-
978- top_bar_layout_->SetMaximumWidth((dash::Style::Instance().GetTileWidth() -12)*2+10);
979-
980- layout_->AddLayout (top_bar_layout_, 0, nux::MINOR_POSITION_LEFT);
981- layout_->SetVerticalInternalMargin(0);
982-
983- SetLayout(layout_);
984-
985- QueueRelayout();
986- NeedRedraw();
987- }
988-
989- void FilterExpanderLabel::DoExpandChange (bool change)
990- {
991- if (contents_)
992- contents_->SetVisible(change);
993-
994- QueueRelayout();
995- }
996-
997- void FilterExpanderLabel::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
998- nux::Geometry geo = GetGeometry();
999-
1000- GfxContext.PushClippingRectangle(geo);
1001- nux::GetPainter().PaintBackground(GfxContext, geo);
1002- GfxContext.PopClippingRectangle();
1003- }
1004-
1005- void FilterExpanderLabel::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
1006- GfxContext.PushClippingRectangle(GetGeometry());
1007-
1008- GetLayout()->ProcessDraw(GfxContext, force_draw);
1009-
1010- GfxContext.PopClippingRectangle();
1011- }
1012-
1013- void FilterExpanderLabel::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
1014- nux::View::PostDraw(GfxContext, force_draw);
1015- }
1016-
1017-};
1018+FilterExpanderLabel::FilterExpanderLabel(std::string const& label, NUX_FILE_LINE_DECL)
1019+ : FilterWidget(NUX_FILE_LINE_PARAM)
1020+ , expanded(true)
1021+ , layout_(nullptr)
1022+ , top_bar_layout_(nullptr)
1023+ , right_hand_contents_(nullptr)
1024+ , expander_graphic_(nullptr)
1025+ , cairo_label_(nullptr)
1026+ , raw_label_(label)
1027+ , label_("<span size='larger' weight='bold'>" + label + "</span>" + " ▾")
1028+{
1029+ expanded.changed.connect(sigc::mem_fun(this, &FilterExpanderLabel::DoExpandChange));
1030+ BuildLayout();
1031+}
1032+
1033+FilterExpanderLabel::~FilterExpanderLabel()
1034+{
1035+}
1036+
1037+void FilterExpanderLabel::SetLabel(std::string const& label)
1038+{
1039+ raw_label_ = label;
1040+
1041+ label_ = "<span size='larger' weight='bold'>";
1042+ label_ += raw_label_;
1043+ label_ += "</span>";
1044+ label_ += expanded ? " ▾" : " ▸";
1045+ cairo_label_->SetText(label_.c_str());
1046+}
1047+
1048+void FilterExpanderLabel::SetRightHandView(nux::View* view)
1049+{
1050+ view->SetMaximumHeight(30);
1051+
1052+ right_hand_contents_ = view;
1053+ top_bar_layout_->AddView(right_hand_contents_, 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
1054+}
1055+
1056+void FilterExpanderLabel::SetContents(nux::Layout* contents)
1057+{
1058+ contents_.Adopt(contents);
1059+
1060+ layout_->AddLayout(contents_.GetPointer(), 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
1061+ top_bar_layout_->SetTopAndBottomPadding(0);
1062+
1063+ QueueDraw();
1064+}
1065+
1066+void FilterExpanderLabel::BuildLayout()
1067+{
1068+ layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
1069+ top_bar_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
1070+
1071+ cairo_label_ = new nux::StaticText(label_.c_str(), NUX_TRACKER_LOCATION);
1072+ cairo_label_->SetFontName("Ubuntu 10");
1073+ cairo_label_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
1074+ cairo_label_->mouse_down.connect(
1075+ [&](int x, int y, unsigned long button_flags, unsigned long key_flag)
1076+ {
1077+ expanded = !expanded;
1078+ });
1079+
1080+ top_bar_layout_->AddView(cairo_label_, 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
1081+ top_bar_layout_->AddSpace(1, 1);
1082+
1083+ top_bar_layout_->SetMaximumWidth((Style::Instance().GetTileWidth() - 12) * 2 + 10);
1084+
1085+ layout_->AddLayout(top_bar_layout_, 0, nux::MINOR_POSITION_LEFT);
1086+ layout_->SetVerticalInternalMargin(0);
1087+
1088+ SetLayout(layout_);
1089+
1090+ QueueRelayout();
1091+ NeedRedraw();
1092+}
1093+
1094+void FilterExpanderLabel::DoExpandChange(bool change)
1095+{
1096+ label_ = "<span size='larger' weight='bold'>";
1097+ label_ += raw_label_;
1098+ label_ += "</span>";
1099+ label_ += expanded ? " ▾" : " ▸";
1100+
1101+ if (cairo_label_)
1102+ cairo_label_->SetText(label_);
1103+
1104+ if (change and contents_ and !contents_->IsChildOf(layout_))
1105+ {
1106+ layout_->AddLayout(contents_.GetPointer(), 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
1107+ top_bar_layout_->SetTopAndBottomPadding(0);
1108+ }
1109+ else if (!change and contents_ and contents_->IsChildOf(layout_))
1110+ {
1111+ layout_->RemoveChildObject(contents_.GetPointer());
1112+ top_bar_layout_->SetTopAndBottomPadding(0, 10);
1113+ }
1114+
1115+ layout_->ComputeContentSize();
1116+ QueueDraw();
1117+}
1118+
1119+void FilterExpanderLabel::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
1120+{
1121+ nux::Geometry const& geo = GetGeometry();
1122+
1123+ GfxContext.PushClippingRectangle(geo);
1124+ nux::GetPainter().PaintBackground(GfxContext, geo);
1125+ GfxContext.PopClippingRectangle();
1126+}
1127+
1128+void FilterExpanderLabel::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
1129+{
1130+ GfxContext.PushClippingRectangle(GetGeometry());
1131+ GetLayout()->ProcessDraw(GfxContext, force_draw);
1132+ GfxContext.PopClippingRectangle();
1133+}
1134+
1135+} // namespace dash
1136+} // namespace unity
1137
1138=== modified file 'plugins/unityshell/src/FilterExpanderLabel.h'
1139--- plugins/unityshell/src/FilterExpanderLabel.h 2011-10-11 18:18:13 +0000
1140+++ plugins/unityshell/src/FilterExpanderLabel.h 2012-01-11 09:37:33 +0000
1141@@ -20,8 +20,8 @@
1142 *
1143 */
1144
1145-#ifndef UNITY_FILTEREXPANDERLABEL_H
1146-#define UNITY_FILTEREXPANDERLABEL_H
1147+#ifndef UNITYSHELL_FILTEREXPANDERLABEL_H
1148+#define UNITYSHELL_FILTEREXPANDERLABEL_H
1149
1150 #include <Nux/Nux.h>
1151 #include <Nux/GridHLayout.h>
1152@@ -29,39 +29,46 @@
1153 #include <Nux/VLayout.h>
1154 #include <Nux/StaticText.h>
1155
1156-namespace unity {
1157-
1158- class FilterExpanderLabel : public nux::View
1159- {
1160- NUX_DECLARE_OBJECT_TYPE(FilterExpanderLabel, nux::View);
1161- public:
1162- FilterExpanderLabel (std::string label, NUX_FILE_LINE_PROTO);
1163- virtual ~FilterExpanderLabel();
1164-
1165- void SetRightHandView (nux::View *view);
1166- void SetLabel (std::string label);
1167- void SetContents (nux::Layout *layout);
1168-
1169- nux::Property<bool> expanded;
1170-
1171- protected:
1172- virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
1173- virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
1174- virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
1175-
1176- private:
1177- void BuildLayout ();
1178- void DoExpandChange (bool change);
1179-
1180- nux::LinearLayout* layout_;
1181- nux::LinearLayout* top_bar_layout_;
1182- nux::Layout* contents_;
1183- nux::View* right_hand_contents_;
1184- nux::View* expander_graphic_;
1185- nux::StaticText* cairo_label_;
1186- std::string label_;
1187- };
1188-
1189-}
1190-
1191-#endif
1192+#include "FilterWidget.h"
1193+
1194+namespace unity
1195+{
1196+namespace dash
1197+{
1198+
1199+class FilterExpanderLabel : public FilterWidget
1200+{
1201+ NUX_DECLARE_OBJECT_TYPE(FilterExpanderLabel, FilterWidget);
1202+public:
1203+ FilterExpanderLabel(std::string const& label, NUX_FILE_LINE_PROTO);
1204+ virtual ~FilterExpanderLabel();
1205+
1206+ void SetRightHandView(nux::View* view);
1207+ void SetLabel(std::string const& label);
1208+ void SetContents(nux::Layout* layout);
1209+
1210+ nux::Property<bool> expanded;
1211+
1212+protected:
1213+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
1214+ virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
1215+
1216+private:
1217+ void BuildLayout();
1218+ void DoExpandChange(bool change);
1219+
1220+ nux::LinearLayout* layout_;
1221+ nux::LinearLayout* top_bar_layout_;
1222+ nux::View* right_hand_contents_;
1223+ nux::View* expander_graphic_;
1224+ nux::StaticText* cairo_label_;
1225+ std::string raw_label_;
1226+ std::string label_;
1227+
1228+ nux::ObjectPtr<nux::Layout> contents_;
1229+};
1230+
1231+} // namespace dash
1232+} // namespace unity
1233+
1234+#endif // UNITYSHELL_FILTEREXPANDERLABEL_H
1235
1236=== modified file 'plugins/unityshell/src/FilterFactory.cpp'
1237--- plugins/unityshell/src/FilterFactory.cpp 2011-09-06 18:30:26 +0000
1238+++ plugins/unityshell/src/FilterFactory.cpp 2012-01-11 09:37:33 +0000
1239@@ -18,11 +18,9 @@
1240 * Authored by: Gordon Allott <gord.allott@canonical.com>
1241 *
1242 */
1243-#include "config.h"
1244
1245 #include <Nux/Nux.h>
1246 #include <NuxCore/Logger.h>
1247-#include <Nux/View.h>
1248
1249 #include "FilterBasicButton.h"
1250 #include "FilterFactory.h"
1251@@ -30,58 +28,56 @@
1252 #include "FilterMultiRangeWidget.h"
1253 #include "FilterRatingsWidget.h"
1254
1255-namespace {
1256+namespace
1257+{
1258 nux::logging::Logger logger("unity.dash.filterfactory");
1259-}
1260
1261-namespace {
1262 const std::string renderer_type_ratings = "filter-ratings";
1263 const std::string renderer_type_multirange = "filter-multirange";
1264 const std::string renderer_type_check_options = "filter-checkoption";
1265 const std::string renderer_type_radio_options = "filter-radiooption";
1266 }
1267
1268-namespace unity {
1269-
1270- FilterFactory::FilterFactory() {
1271-
1272- }
1273-
1274- FilterFactory::~FilterFactory() {
1275-
1276- }
1277-
1278- nux::View *FilterFactory::WidgetForFilter (dash::Filter::Ptr filter)
1279- {
1280- std::string filter_type = filter->renderer_name;
1281- LOG_DEBUG(logger) << "building filter of type, " << filter_type;
1282-
1283- nux::View *view = NULL;
1284- if (filter_type == renderer_type_check_options)
1285- {
1286- view = static_cast<nux::View *> (new FilterGenre(NUX_TRACKER_LOCATION));
1287- }
1288- else if (filter_type == renderer_type_ratings)
1289- {
1290- view = static_cast<nux::View *> (new FilterRatingsWidget (NUX_TRACKER_LOCATION));
1291- }
1292- else if (filter_type == renderer_type_multirange)
1293- {
1294- view = static_cast<nux::View *> (new FilterMultiRange (NUX_TRACKER_LOCATION));
1295- }
1296- else if (filter_type == renderer_type_radio_options)
1297- {
1298- view = static_cast<nux::View *> (new FilterGenre (NUX_TRACKER_LOCATION));
1299- }
1300- else
1301- {
1302- LOG_WARNING(logger) << "Do not understand filter of type \""
1303- << filter_type
1304- << "\"";
1305- }
1306-
1307- dynamic_cast<FilterWidget *>(view)->SetFilter (filter);
1308-
1309- return view;
1310- }
1311+namespace unity
1312+{
1313+namespace dash
1314+{
1315+
1316+nux::View* FilterFactory::WidgetForFilter(Filter::Ptr const& filter)
1317+{
1318+ std::string filter_type(filter->renderer_name);
1319+ LOG_DEBUG(logger) << "building filter of type, " << filter_type;
1320+
1321+ FilterWidget* widget = nullptr;
1322+ if (filter_type == renderer_type_check_options)
1323+ {
1324+ widget = new FilterGenre(NUX_TRACKER_LOCATION);
1325+ }
1326+ else if (filter_type == renderer_type_ratings)
1327+ {
1328+ widget = new FilterRatingsWidget(NUX_TRACKER_LOCATION);
1329+ }
1330+ else if (filter_type == renderer_type_multirange)
1331+ {
1332+ widget = new FilterMultiRange(NUX_TRACKER_LOCATION);
1333+ }
1334+ else if (filter_type == renderer_type_radio_options)
1335+ {
1336+ widget = new FilterGenre(NUX_TRACKER_LOCATION);
1337+ }
1338+ else
1339+ {
1340+ LOG_WARNING(logger) << "Do not understand filter of type \""
1341+ << filter_type
1342+ << "\"";
1343+ }
1344+
1345+ if (widget)
1346+ widget->SetFilter(filter);
1347+
1348+ return widget;
1349 }
1350+
1351+} // namespace dash
1352+} // namespace unity
1353+
1354
1355=== modified file 'plugins/unityshell/src/FilterFactory.h'
1356--- plugins/unityshell/src/FilterFactory.h 2011-08-04 21:41:10 +0000
1357+++ plugins/unityshell/src/FilterFactory.h 2012-01-11 09:37:33 +0000
1358@@ -19,19 +19,25 @@
1359 *
1360 */
1361
1362-
1363-
1364-#ifndef FILTERFACTORY_H
1365-#define FILTERFACTORY_H
1366-namespace unity {
1367-
1368- class FilterFactory
1369- {
1370- public:
1371- FilterFactory();
1372- virtual ~FilterFactory();
1373-
1374- nux::View *WidgetForFilter (dash::Filter::Ptr filter);
1375- };
1376+#ifndef UNITYSHELL_FILTERFACTORY_H
1377+#define UNITYSHELL_FILTERFACTORY_H
1378+
1379+#include <Nux/View.h>
1380+#include <UnityCore/Filter.h>
1381+
1382+namespace unity
1383+{
1384+namespace dash
1385+{
1386+
1387+class FilterFactory
1388+{
1389+public:
1390+ nux::View* WidgetForFilter(Filter::Ptr const& filter);
1391 };
1392-#endif // FILTERFACTORY_H
1393+
1394+} // namespace dash
1395+} // namespace unity
1396+
1397+#endif // UNITYSHELL_FILTERFACTORY_H
1398+
1399
1400=== modified file 'plugins/unityshell/src/FilterGenreButton.cpp'
1401--- plugins/unityshell/src/FilterGenreButton.cpp 2011-10-11 18:18:13 +0000
1402+++ plugins/unityshell/src/FilterGenreButton.cpp 2012-01-11 09:37:33 +0000
1403@@ -18,62 +18,55 @@
1404 * Authored by: Gordon Allott <gord.allott@canonical.com>
1405 *
1406 */
1407-#include "config.h"
1408-
1409-#include <Nux/Nux.h>
1410
1411 #include "FilterGenreButton.h"
1412
1413-namespace unity {
1414- FilterGenreButton::FilterGenreButton (const std::string label, NUX_FILE_LINE_DECL)
1415- : FilterBasicButton(label, NUX_FILE_LINE_PARAM) {
1416- InitTheme();
1417-
1418- state_change.connect ([&] (Button* button) {
1419- bool tmp_active = Active();
1420- if (filter_ != NULL)
1421- filter_->active = tmp_active;
1422- });
1423- }
1424-
1425- FilterGenreButton::FilterGenreButton (NUX_FILE_LINE_DECL)
1426- : FilterBasicButton(NUX_FILE_LINE_PARAM) {
1427- InitTheme();
1428-
1429- state_change.connect ([&] (Button* button) {
1430- bool tmp_active = Active();
1431- if (filter_ != NULL)
1432- filter_->active = tmp_active;
1433- });
1434- }
1435-
1436-
1437- void FilterGenreButton::SetFilter (dash::FilterOption::Ptr filter)
1438- {
1439- filter_ = filter;
1440-
1441- bool tmp_active = filter_->active;
1442- SetActive(tmp_active);
1443- filter_->active.changed.connect ([&] (bool is_active) {
1444- SetActive(is_active);
1445- });
1446- }
1447-
1448- dash::FilterOption::Ptr FilterGenreButton::GetFilter()
1449- {
1450- return filter_;
1451- }
1452-
1453- void FilterGenreButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
1454- FilterBasicButton::Draw(GfxContext, force_draw);
1455- }
1456-
1457- void FilterGenreButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
1458- FilterBasicButton::DrawContent(GfxContext, force_draw);
1459- }
1460-
1461- void FilterGenreButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
1462- FilterBasicButton::PostDraw(GfxContext, force_draw);
1463- }
1464-
1465-}
1466+namespace unity
1467+{
1468+namespace dash
1469+{
1470+
1471+FilterGenreButton::FilterGenreButton(std::string const& label, NUX_FILE_LINE_DECL)
1472+ : FilterBasicButton(label, NUX_FILE_LINE_PARAM)
1473+{
1474+ InitTheme();
1475+
1476+ state_change.connect([&](nux::Button* button)
1477+ {
1478+ if (filter_)
1479+ filter_->active = Active();
1480+ });
1481+}
1482+
1483+FilterGenreButton::FilterGenreButton(NUX_FILE_LINE_DECL)
1484+ : FilterBasicButton(NUX_FILE_LINE_PARAM)
1485+{
1486+ InitTheme();
1487+
1488+ state_change.connect([&](nux::Button* button)
1489+ {
1490+ if (filter_)
1491+ filter_->active = Active();
1492+ });
1493+}
1494+
1495+
1496+void FilterGenreButton::SetFilter(FilterOption::Ptr const& filter)
1497+{
1498+ filter_ = filter;
1499+
1500+ SetActive(filter_->active);
1501+
1502+ filter_->active.changed.connect([&](bool is_active)
1503+ {
1504+ SetActive(is_active);
1505+ });
1506+}
1507+
1508+FilterOption::Ptr FilterGenreButton::GetFilter()
1509+{
1510+ return filter_;
1511+}
1512+
1513+} // namespace dash
1514+} // namespace unity
1515
1516=== modified file 'plugins/unityshell/src/FilterGenreButton.h'
1517--- plugins/unityshell/src/FilterGenreButton.h 2011-10-11 18:18:13 +0000
1518+++ plugins/unityshell/src/FilterGenreButton.h 2012-01-11 09:37:33 +0000
1519@@ -19,10 +19,8 @@
1520 *
1521 */
1522
1523-
1524-
1525-#ifndef FILTERGENREBUTTON_H
1526-#define FILTERGENREBUTTON_H
1527+#ifndef UNITYSHELL_FILTERGENREBUTTON_H
1528+#define UNITYSHELL_FILTERGENREBUTTON_H
1529
1530 #include <Nux/Nux.h>
1531 #include <Nux/ToggleButton.h>
1532@@ -30,24 +28,26 @@
1533 #include "FilterWidget.h"
1534 #include "FilterBasicButton.h"
1535
1536-namespace unity {
1537-
1538- class FilterGenreButton : public FilterBasicButton {
1539- public:
1540- FilterGenreButton (const std::string label, NUX_FILE_LINE_PROTO);
1541- FilterGenreButton (NUX_FILE_LINE_PROTO);
1542-
1543- void SetFilter (dash::FilterOption::Ptr filter);
1544- dash::FilterOption::Ptr GetFilter();
1545-
1546- protected:
1547- virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
1548- virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
1549- virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
1550-
1551- private:
1552- dash::FilterOption::Ptr filter_;
1553- };
1554-
1555-}
1556+namespace unity
1557+{
1558+namespace dash
1559+{
1560+
1561+class FilterGenreButton : public FilterBasicButton
1562+{
1563+public:
1564+ FilterGenreButton(std::string const& label, NUX_FILE_LINE_PROTO);
1565+ FilterGenreButton(NUX_FILE_LINE_PROTO);
1566+
1567+ void SetFilter(FilterOption::Ptr const& filter);
1568+ FilterOption::Ptr GetFilter();
1569+
1570+private:
1571+ FilterOption::Ptr filter_;
1572+};
1573+
1574+} // namespace dash
1575+} // namespace unity
1576+
1577 #endif // FILTERGENREBUTTON_H
1578+
1579
1580=== modified file 'plugins/unityshell/src/FilterGenreWidget.cpp'
1581--- plugins/unityshell/src/FilterGenreWidget.cpp 2011-10-25 16:32:49 +0000
1582+++ plugins/unityshell/src/FilterGenreWidget.cpp 2012-01-11 09:37:33 +0000
1583@@ -20,152 +20,121 @@
1584 *
1585 */
1586
1587-#include "config.h"
1588-
1589-#include <Nux/Nux.h>
1590-#include <NuxCore/Logger.h>
1591-
1592 #include <glib.h>
1593 #include <glib/gi18n-lib.h>
1594+#include <UnityCore/GLibWrapper.h>
1595
1596+#include "DashStyle.h"
1597 #include "FilterGenreWidget.h"
1598 #include "FilterGenreButton.h"
1599 #include "FilterBasicButton.h"
1600-#include "DashStyle.h"
1601
1602 namespace unity
1603 {
1604-namespace
1605+namespace dash
1606 {
1607-nux::logging::Logger logger("unity.dash.filter");
1608-}
1609
1610 NUX_IMPLEMENT_OBJECT_TYPE(FilterGenre);
1611
1612- FilterGenre::FilterGenre (NUX_FILE_LINE_DECL)
1613- : FilterExpanderLabel (_("Categories"), NUX_FILE_LINE_PARAM)
1614- , all_selected (false)
1615- {
1616- InitTheme();
1617-
1618- all_button_ = new FilterBasicButton(_("All"), NUX_TRACKER_LOCATION);
1619- all_button_->state_change.connect(sigc::mem_fun(this, &FilterGenre::OnAllActivated));
1620- all_button_->SetLabel(_("All"));
1621-
1622- genre_layout_ = new nux::GridHLayout(NUX_TRACKER_LOCATION);
1623- genre_layout_->ForceChildrenSize(true);
1624- genre_layout_->MatchContentSize(true);
1625- genre_layout_->SetSpaceBetweenChildren (10, 12);
1626- genre_layout_->SetTopAndBottomPadding (12);
1627- genre_layout_->EnablePartialVisibility (false);
1628- genre_layout_->SetChildrenSize (dash::Style::Instance().GetTileWidth() - 12, 32);
1629-
1630- SetRightHandView(all_button_);
1631- SetContents(genre_layout_);
1632- }
1633-
1634- FilterGenre::~FilterGenre()
1635- {
1636- }
1637-
1638- void FilterGenre::SetFilter(dash::Filter::Ptr filter)
1639- {
1640- filter_ = std::static_pointer_cast<dash::CheckOptionFilter>(filter);
1641-
1642- filter_->option_added.connect (sigc::mem_fun (this, &FilterGenre::OnOptionAdded));
1643- filter_->option_removed.connect(sigc::mem_fun (this, &FilterGenre::OnOptionRemoved));
1644-
1645- // finally - make sure we are up-todate with our filter list
1646- dash::CheckOptionFilter::CheckOptions::iterator it;
1647- dash::CheckOptionFilter::CheckOptions options = filter_->options;
1648- for (it = options.begin(); it < options.end(); it++)
1649- OnOptionAdded(*it);
1650-
1651- SetLabel(filter_->name);
1652- }
1653-
1654- void FilterGenre::OnOptionAdded(dash::FilterOption::Ptr new_filter)
1655- {
1656- std::string tmp_label = new_filter->name;
1657-
1658- char* escape = g_markup_escape_text(tmp_label.c_str(), -1);
1659- std::string label = escape;
1660- g_free(escape);
1661-
1662- FilterGenreButton* button = new FilterGenreButton (label, NUX_TRACKER_LOCATION);
1663- button->SetFilter (new_filter);
1664- genre_layout_->AddView (button, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
1665- buttons_.push_back (button);
1666- }
1667-
1668- void FilterGenre::OnOptionRemoved(dash::FilterOption::Ptr removed_filter)
1669- {
1670- std::vector<FilterGenreButton*>::iterator it;
1671- FilterGenreButton* found_filter = NULL;
1672- for ( it=buttons_.begin() ; it < buttons_.end(); it++ )
1673- {
1674- if ((*it)->GetFilter() == removed_filter)
1675- {
1676- found_filter = *it;
1677- break;
1678- }
1679- }
1680-
1681- if (found_filter)
1682+FilterGenre::FilterGenre(NUX_FILE_LINE_DECL)
1683+ : FilterExpanderLabel(_("Categories"), NUX_FILE_LINE_PARAM)
1684+{
1685+ InitTheme();
1686+
1687+ all_button_ = new FilterAllButton(NUX_TRACKER_LOCATION);
1688+
1689+ genre_layout_ = new nux::GridHLayout(NUX_TRACKER_LOCATION);
1690+ genre_layout_->ForceChildrenSize(true);
1691+ genre_layout_->MatchContentSize(true);
1692+ genre_layout_->SetSpaceBetweenChildren(10, 12);
1693+ genre_layout_->SetTopAndBottomPadding(12);
1694+ genre_layout_->EnablePartialVisibility(false);
1695+ genre_layout_->SetChildrenSize(Style::Instance().GetTileWidth() - 12, 32);
1696+
1697+ SetRightHandView(all_button_);
1698+ SetContents(genre_layout_);
1699+}
1700+
1701+FilterGenre::~FilterGenre()
1702+{
1703+}
1704+
1705+void FilterGenre::SetFilter(Filter::Ptr const& filter)
1706+{
1707+ filter_ = std::static_pointer_cast<CheckOptionFilter>(filter);
1708+
1709+ all_button_->SetFilter(filter_);
1710+ expanded = !filter_->collapsed();
1711+
1712+ filter_->option_added.connect(sigc::mem_fun(this, &FilterGenre::OnOptionAdded));
1713+ filter_->option_removed.connect(sigc::mem_fun(this, &FilterGenre::OnOptionRemoved));
1714+
1715+ // finally - make sure we are up-todate with our filter list
1716+ for (auto it : filter_->options())
1717+ OnOptionAdded(it);
1718+
1719+ SetLabel(filter_->name);
1720+}
1721+
1722+void FilterGenre::OnOptionAdded(FilterOption::Ptr const& new_filter)
1723+{
1724+ std::string tmp_label(new_filter->name);
1725+
1726+ glib::String escape(g_markup_escape_text(tmp_label.c_str(), -1));
1727+ std::string label(escape.Value());
1728+
1729+ FilterGenreButton* button = new FilterGenreButton(label, NUX_TRACKER_LOCATION);
1730+ button->SetFilter(new_filter);
1731+ genre_layout_->AddView(button, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
1732+ buttons_.push_back(button);
1733+}
1734+
1735+void FilterGenre::OnOptionRemoved(FilterOption::Ptr const& removed_filter)
1736+{
1737+ for (auto it=buttons_.begin() ; it != buttons_.end(); ++it)
1738+ {
1739+ if ((*it)->GetFilter() == removed_filter)
1740 {
1741 genre_layout_->RemoveChildObject(*it);
1742 buttons_.erase(it);
1743+ break;
1744 }
1745 }
1746-
1747- std::string FilterGenre::GetFilterType ()
1748- {
1749- return "FilterBasicButton";
1750- }
1751-
1752- void FilterGenre::InitTheme()
1753- {
1754- //FIXME - build theme here - store images, cache them, fun fun fun
1755- }
1756-
1757- void FilterGenre::OnAllActivated(nux::View *view)
1758- {
1759- if (filter_)
1760- filter_->Clear();
1761- }
1762-
1763- void FilterGenre::OnGenreActivated(nux::View *view)
1764- {
1765- // just check to see if all the filters are active or not
1766- // if they are, then set the all status to true
1767- }
1768-
1769- void FilterGenre::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
1770- nux::Geometry geo = GetGeometry();
1771- nux::Color col(0.2f, 0.2f, 0.2f, 0.2f);
1772-
1773- GfxContext.PushClippingRectangle(geo);
1774- nux::GetPainter().PaintBackground(GfxContext, geo);
1775-
1776- nux::GetPainter().Draw2DLine(GfxContext,
1777- geo.x, geo.y + geo.height - 1,
1778- geo.x + geo.width, geo.y + geo.height - 1,
1779- col,
1780- col);
1781-
1782- GfxContext.PopClippingRectangle();
1783- }
1784-
1785- void FilterGenre::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
1786- GfxContext.PushClippingRectangle(GetGeometry());
1787-
1788- GetLayout()->ProcessDraw(GfxContext, force_draw);
1789-
1790- GfxContext.PopClippingRectangle();
1791- }
1792-
1793- void FilterGenre::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
1794- nux::View::PostDraw(GfxContext, force_draw);
1795- }
1796-
1797-};
1798+}
1799+
1800+std::string FilterGenre::GetFilterType()
1801+{
1802+ return "FilterBasicButton";
1803+}
1804+
1805+void FilterGenre::InitTheme()
1806+{
1807+ //FIXME - build theme here - store images, cache them, fun fun fun
1808+}
1809+
1810+void FilterGenre::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
1811+{
1812+ nux::Geometry const& geo = GetGeometry();
1813+ nux::Color col(0.2f, 0.2f, 0.2f, 0.2f);
1814+
1815+ GfxContext.PushClippingRectangle(geo);
1816+ nux::GetPainter().PaintBackground(GfxContext, geo);
1817+
1818+ nux::GetPainter().Draw2DLine(GfxContext,
1819+ geo.x, geo.y + geo.height - 1,
1820+ geo.x + geo.width, geo.y + geo.height - 1,
1821+ col,
1822+ col);
1823+
1824+ GfxContext.PopClippingRectangle();
1825+}
1826+
1827+void FilterGenre::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
1828+{
1829+ GfxContext.PushClippingRectangle(GetGeometry());
1830+ GetLayout()->ProcessDraw(GfxContext, force_draw);
1831+ GfxContext.PopClippingRectangle();
1832+}
1833+
1834+} // namespace dash
1835+} // namespace unity
1836
1837=== modified file 'plugins/unityshell/src/FilterGenreWidget.h'
1838--- plugins/unityshell/src/FilterGenreWidget.h 2011-10-11 18:18:13 +0000
1839+++ plugins/unityshell/src/FilterGenreWidget.h 2012-01-11 09:37:33 +0000
1840@@ -20,10 +20,8 @@
1841 *
1842 */
1843
1844-
1845-
1846-#ifndef FILTERGENREWIDGET_H
1847-#define FILTERGENREWIDGET_H
1848+#ifndef UNITYSHELL_FILTERGENREWIDGET_H
1849+#define UNITYSHELL_FILTERGENREWIDGET_H
1850
1851 #include <Nux/Nux.h>
1852 #include <Nux/GridHLayout.h>
1853@@ -32,45 +30,45 @@
1854
1855 #include <UnityCore/CheckOptionFilter.h>
1856
1857-#include "FilterWidget.h"
1858+#include "FilterAllButton.h"
1859 #include "FilterExpanderLabel.h"
1860
1861-namespace unity {
1862- class FilterBasicButton;
1863- class FilterGenreButton;
1864-
1865- class FilterGenre : public FilterExpanderLabel, public FilterWidget
1866- {
1867- NUX_DECLARE_OBJECT_TYPE(FilterGenre, FilterExpanderLabel);
1868- public:
1869- FilterGenre (NUX_FILE_LINE_PROTO);
1870- virtual ~FilterGenre();
1871-
1872- void SetFilter (dash::Filter::Ptr filter);
1873- std::string GetFilterType ();
1874-
1875- nux::Property<bool> all_selected;
1876-
1877- protected:
1878- virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
1879- virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
1880- virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
1881-
1882- void InitTheme ();
1883-
1884- private:
1885- void OnAllActivated(nux::View* view);
1886- void OnGenreActivated(nux::View* view);
1887- void OnOptionAdded(dash::FilterOption::Ptr new_filter);
1888- void OnOptionRemoved(dash::FilterOption::Ptr removed_filter);
1889-
1890- nux::GridHLayout* genre_layout_;
1891- FilterBasicButton* all_button_;
1892-
1893- std::vector<FilterGenreButton*> buttons_;
1894- dash::CheckOptionFilter::Ptr filter_;
1895- };
1896-
1897-}
1898-
1899-#endif // FILTERGENRESWIDGET_H
1900+namespace unity
1901+{
1902+namespace dash
1903+{
1904+
1905+class FilterBasicButton;
1906+class FilterGenreButton;
1907+
1908+class FilterGenre : public FilterExpanderLabel
1909+{
1910+ NUX_DECLARE_OBJECT_TYPE(FilterGenre, FilterExpanderLabel);
1911+public:
1912+ FilterGenre(NUX_FILE_LINE_PROTO);
1913+ virtual ~FilterGenre();
1914+
1915+ void SetFilter(Filter::Ptr const& filter);
1916+ std::string GetFilterType();
1917+
1918+protected:
1919+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
1920+ virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
1921+
1922+ void InitTheme();
1923+
1924+private:
1925+ void OnOptionAdded(FilterOption::Ptr const& new_filter);
1926+ void OnOptionRemoved(FilterOption::Ptr const& removed_filter);
1927+
1928+ nux::GridHLayout* genre_layout_;
1929+ FilterAllButton* all_button_;
1930+
1931+ std::vector<FilterGenreButton*> buttons_;
1932+ CheckOptionFilter::Ptr filter_;
1933+};
1934+
1935+} // namespace dash
1936+} // namespace unity
1937+
1938+#endif // UNITYSHELL_FILTERGENRESWIDGET_H
1939
1940=== modified file 'plugins/unityshell/src/FilterMultiRangeButton.cpp'
1941--- plugins/unityshell/src/FilterMultiRangeButton.cpp 2011-11-08 19:41:00 +0000
1942+++ plugins/unityshell/src/FilterMultiRangeButton.cpp 2012-01-11 09:37:33 +0000
1943@@ -25,187 +25,181 @@
1944 #include "DashStyle.h"
1945 #include "FilterMultiRangeButton.h"
1946
1947-namespace unity {
1948- FilterMultiRangeButton::FilterMultiRangeButton (const std::string label, NUX_FILE_LINE_DECL)
1949- : nux::ToggleButton(label, NUX_FILE_LINE_PARAM)
1950- , prelight_ (NULL)
1951- , active_ (NULL)
1952- , normal_ (NULL)
1953- , has_arrow_ (MULTI_RANGE_ARROW_NONE)
1954- , side_ (MULTI_RANGE_CENTER)
1955- {
1956- InitTheme();
1957- state_change.connect (sigc::mem_fun(this, &FilterMultiRangeButton::OnActivated));
1958- }
1959-
1960- FilterMultiRangeButton::FilterMultiRangeButton (NUX_FILE_LINE_DECL)
1961- : nux::ToggleButton(NUX_FILE_LINE_PARAM)
1962- , prelight_ (NULL)
1963- , active_ (NULL)
1964- , normal_ (NULL)
1965- , has_arrow_ (MULTI_RANGE_ARROW_NONE)
1966- , side_ (MULTI_RANGE_CENTER)
1967- {
1968- InitTheme();
1969- state_change.connect (sigc::mem_fun(this, &FilterMultiRangeButton::OnActivated));
1970- }
1971-
1972- FilterMultiRangeButton::~FilterMultiRangeButton()
1973- {
1974- delete prelight_;
1975- delete normal_;
1976- delete active_;
1977- }
1978-
1979- void FilterMultiRangeButton::OnActivated (nux::Area *area)
1980- {
1981- bool tmp_active = Active();
1982- if (filter_ != NULL)
1983- filter_->active = tmp_active;
1984- }
1985-
1986- void FilterMultiRangeButton::OnActiveChanged(bool value)
1987- {
1988- NeedRedraw();
1989- }
1990-
1991- void FilterMultiRangeButton::SetFilter (dash::FilterOption::Ptr filter)
1992- {
1993- filter_ = filter;
1994- bool tmp_active = filter_->active;
1995- SetActive(tmp_active);
1996- }
1997-
1998- dash::FilterOption::Ptr FilterMultiRangeButton::GetFilter()
1999- {
2000- return filter_;
2001- }
2002-
2003- void FilterMultiRangeButton::SetVisualSide (MultiRangeSide side)
2004- {
2005- side_ = side;
2006- prelight_->Invalidate(GetGeometry());
2007- active_->Invalidate(GetGeometry());
2008- normal_->Invalidate(GetGeometry());
2009- }
2010-
2011- void FilterMultiRangeButton::SetHasArrow (MultiRangeArrow value)
2012- {
2013- has_arrow_ = value;
2014- active_->Invalidate(GetGeometry());
2015- NeedRedraw();
2016- }
2017-
2018- long FilterMultiRangeButton::ComputeContentSize()
2019- {
2020- if (prelight_ == NULL)
2021- {
2022- InitTheme();
2023- }
2024- long ret = nux::ToggleButton::ComputeContentSize();
2025- if (cached_geometry_ != GetGeometry())
2026- {
2027- prelight_->Invalidate(GetGeometry());
2028- active_->Invalidate(GetGeometry());
2029- normal_->Invalidate(GetGeometry());
2030- }
2031-
2032- cached_geometry_ = GetGeometry();
2033- return ret;
2034- }
2035-
2036- void FilterMultiRangeButton::InitTheme()
2037- {
2038- if (prelight_ == NULL)
2039- {
2040- prelight_ = new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &FilterMultiRangeButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT));
2041- active_ = new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &FilterMultiRangeButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED));
2042- normal_ = new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &FilterMultiRangeButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL));
2043- }
2044-
2045- SetMinimumHeight(32);
2046- }
2047-
2048- void FilterMultiRangeButton::RedrawTheme (nux::Geometry const& geom, cairo_t *cr, nux::ButtonVisualState faked_state)
2049- {
2050- std::string name = "10";
2051- std::stringstream final;
2052-
2053- if (filter_)
2054- {
2055- name = filter_->name;
2056- final << "<small>" << name << "</small>";
2057- }
2058-
2059- dash::Arrow arrow;
2060- if (has_arrow_ == MULTI_RANGE_ARROW_NONE)
2061- arrow = dash::Arrow::NONE;
2062- else if (has_arrow_ == MULTI_RANGE_ARROW_LEFT)
2063- arrow = dash::Arrow::LEFT;
2064- else if (has_arrow_ == MULTI_RANGE_ARROW_BOTH)
2065- arrow = dash::Arrow::BOTH;
2066- else
2067- arrow = dash::Arrow::RIGHT;
2068-
2069- dash::Segment segment;
2070- if (side_ == MULTI_RANGE_SIDE_LEFT)
2071- segment = dash::Segment::LEFT;
2072- else if (side_ == MULTI_RANGE_CENTER)
2073- segment = dash::Segment::MIDDLE;
2074- else
2075- segment = dash::Segment::RIGHT;
2076-
2077- dash::Style::Instance().MultiRangeSegment(cr, faked_state, final.str(), arrow, segment);
2078- NeedRedraw();
2079- }
2080-
2081- void FilterMultiRangeButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
2082- gPainter.PaintBackground(GfxContext, GetGeometry());
2083- // set up our texture mode
2084- nux::TexCoordXForm texxform;
2085- texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
2086- texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
2087-
2088- // clear what is behind us
2089- unsigned int alpha = 0, src = 0, dest = 0;
2090- GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
2091- GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2092-
2093- nux::Color col = nux::color::Black;
2094- col.alpha = 0;
2095- GfxContext.QRP_Color(GetGeometry().x,
2096- GetGeometry().y,
2097- GetGeometry().width,
2098- GetGeometry().height,
2099- col);
2100-
2101- nux::BaseTexture *texture = normal_->GetTexture();
2102- //FIXME - dashstyle does not give us a focused state yet, so ignore
2103- //~ if (state == nux::ButtonVisualState::NUX_VISUAL_STATE_PRELIGHT)
2104- //~ {
2105- //~ texture = prelight_->GetTexture();
2106- //~ }
2107- if (Active())
2108- {
2109- texture = active_->GetTexture();
2110- }
2111-
2112- GfxContext.QRP_1Tex(GetGeometry().x,
2113- GetGeometry().y,
2114- GetGeometry().width,
2115- GetGeometry().height,
2116- texture->GetDeviceTexture(),
2117- texxform,
2118- nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
2119- GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
2120- }
2121-
2122- void FilterMultiRangeButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
2123- //nux::ToggleButton::DrawContent(GfxContext, force_draw);
2124- }
2125-
2126- void FilterMultiRangeButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
2127- nux::ToggleButton::PostDraw(GfxContext, force_draw);
2128- }
2129-
2130-}
2131+namespace unity
2132+{
2133+namespace dash
2134+{
2135+
2136+FilterMultiRangeButton::FilterMultiRangeButton(std::string const& label, NUX_FILE_LINE_DECL)
2137+ : nux::ToggleButton(label, NUX_FILE_LINE_PARAM)
2138+ , has_arrow_(MultiRangeArrow::NONE)
2139+ , side_(MultiRangeSide::CENTER)
2140+{
2141+ InitTheme();
2142+ state_change.connect(sigc::mem_fun(this, &FilterMultiRangeButton::OnActivated));
2143+}
2144+
2145+FilterMultiRangeButton::FilterMultiRangeButton(NUX_FILE_LINE_DECL)
2146+ : nux::ToggleButton(NUX_FILE_LINE_PARAM)
2147+ , has_arrow_(MultiRangeArrow::NONE)
2148+ , side_(MultiRangeSide::CENTER)
2149+{
2150+ InitTheme();
2151+ state_change.connect(sigc::mem_fun(this, &FilterMultiRangeButton::OnActivated));
2152+}
2153+
2154+FilterMultiRangeButton::~FilterMultiRangeButton()
2155+{
2156+}
2157+
2158+void FilterMultiRangeButton::OnActivated(nux::Area* area)
2159+{
2160+ if (filter_)
2161+ filter_->active = Active();
2162+}
2163+
2164+void FilterMultiRangeButton::OnActiveChanged(bool value)
2165+{
2166+ NeedRedraw();
2167+}
2168+
2169+void FilterMultiRangeButton::SetFilter(FilterOption::Ptr const& filter)
2170+{
2171+ filter_ = filter;
2172+ SetActive(filter_->active);
2173+}
2174+
2175+FilterOption::Ptr FilterMultiRangeButton::GetFilter()
2176+{
2177+ return filter_;
2178+}
2179+
2180+void FilterMultiRangeButton::SetVisualSide(MultiRangeSide side)
2181+{
2182+ nux::Geometry const& geo = GetGeometry();
2183+
2184+ side_ = side;
2185+ prelight_->Invalidate(geo);
2186+ active_->Invalidate(geo);
2187+ normal_->Invalidate(geo);
2188+}
2189+
2190+void FilterMultiRangeButton::SetHasArrow(MultiRangeArrow value)
2191+{
2192+ has_arrow_ = value;
2193+ active_->Invalidate(GetGeometry());
2194+ NeedRedraw();
2195+}
2196+
2197+long FilterMultiRangeButton::ComputeContentSize()
2198+{
2199+ if (!active_)
2200+ {
2201+ InitTheme();
2202+ }
2203+ long ret = nux::ToggleButton::ComputeContentSize();
2204+ nux::Geometry const& geo = GetGeometry();
2205+ if (cached_geometry_ != geo)
2206+ {
2207+ prelight_->Invalidate(geo);
2208+ active_->Invalidate(geo);
2209+ normal_->Invalidate(geo);
2210+ cached_geometry_ = geo;
2211+ }
2212+
2213+ return ret;
2214+}
2215+
2216+void FilterMultiRangeButton::InitTheme()
2217+{
2218+ if (!active_)
2219+ {
2220+ nux::Geometry const& geo = GetGeometry();
2221+ active_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterMultiRangeButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED)));
2222+ normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterMultiRangeButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
2223+ prelight_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterMultiRangeButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
2224+ }
2225+
2226+ SetMinimumHeight(32);
2227+}
2228+
2229+void FilterMultiRangeButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state)
2230+{
2231+ std::string name("10");
2232+ std::stringstream final;
2233+
2234+ if (filter_)
2235+ {
2236+ name = filter_->name;
2237+ final << "<small>" << name << "</small>";
2238+ }
2239+
2240+ Arrow arrow;
2241+ if (has_arrow_ == MultiRangeArrow::NONE)
2242+ arrow = Arrow::NONE;
2243+ else if (has_arrow_ == MultiRangeArrow::LEFT)
2244+ arrow = Arrow::LEFT;
2245+ else if (has_arrow_ == MultiRangeArrow::BOTH)
2246+ arrow = Arrow::BOTH;
2247+ else
2248+ arrow = Arrow::RIGHT;
2249+
2250+ Segment segment;
2251+ if (side_ == MultiRangeSide::LEFT)
2252+ segment = Segment::LEFT;
2253+ else if (side_ == MultiRangeSide::CENTER)
2254+ segment = Segment::MIDDLE;
2255+ else
2256+ segment = Segment::RIGHT;
2257+
2258+ Style::Instance().MultiRangeSegment(cr, faked_state, final.str(), arrow, segment);
2259+ NeedRedraw();
2260+}
2261+
2262+void FilterMultiRangeButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
2263+{
2264+ nux::Geometry const& geo = GetGeometry();
2265+
2266+ gPainter.PaintBackground(GfxContext, geo);
2267+ // set up our texture mode
2268+ nux::TexCoordXForm texxform;
2269+ texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
2270+ texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
2271+
2272+ // clear what is behind us
2273+ unsigned int alpha = 0, src = 0, dest = 0;
2274+ GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
2275+ GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2276+
2277+ nux::Color col = nux::color::Black;
2278+ col.alpha = 0;
2279+ GfxContext.QRP_Color(geo.x,
2280+ geo.y,
2281+ geo.width,
2282+ geo.height,
2283+ col);
2284+
2285+ nux::BaseTexture* texture = normal_->GetTexture();
2286+ //FIXME - dashstyle does not give us a focused state yet, so ignore
2287+ if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
2288+ {
2289+ texture = prelight_->GetTexture();
2290+ }
2291+
2292+ if (Active())
2293+ {
2294+ texture = active_->GetTexture();
2295+ }
2296+
2297+ GfxContext.QRP_1Tex(geo.x,
2298+ geo.y,
2299+ geo.width,
2300+ geo.height,
2301+ texture->GetDeviceTexture(),
2302+ texxform,
2303+ nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
2304+ GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
2305+}
2306+
2307+} // namespace dash
2308+} // namespace unity
2309
2310=== modified file 'plugins/unityshell/src/FilterMultiRangeButton.h'
2311--- plugins/unityshell/src/FilterMultiRangeButton.h 2011-10-25 16:21:21 +0000
2312+++ plugins/unityshell/src/FilterMultiRangeButton.h 2012-01-11 09:37:33 +0000
2313@@ -19,10 +19,10 @@
2314 *
2315 */
2316
2317-
2318-
2319-#ifndef FILTERMULTIRANGEBUTTON_H
2320-#define FILTERMULTIRANGEBUTTON_H
2321+#ifndef UNITYSHELL_FILTERMULTIRANGEBUTTON_H
2322+#define UNITYSHELL_FILTERMULTIRANGEBUTTON_H
2323+
2324+#include <memory>
2325
2326 #include <Nux/Nux.h>
2327 #include <Nux/CairoWrapper.h>
2328@@ -31,57 +31,62 @@
2329
2330 #include "FilterWidget.h"
2331
2332-namespace unity {
2333-
2334- typedef enum {
2335- MULTI_RANGE_SIDE_LEFT,
2336- MULTI_RANGE_SIDE_RIGHT,
2337- MULTI_RANGE_CENTER
2338- } MultiRangeSide;
2339-
2340- typedef enum {
2341- MULTI_RANGE_ARROW_LEFT,
2342- MULTI_RANGE_ARROW_RIGHT,
2343- MULTI_RANGE_ARROW_BOTH,
2344- MULTI_RANGE_ARROW_NONE
2345- } MultiRangeArrow;
2346-
2347- class FilterMultiRangeButton : public nux::ToggleButton {
2348- public:
2349-
2350- FilterMultiRangeButton (const std::string label, NUX_FILE_LINE_PROTO);
2351- FilterMultiRangeButton (NUX_FILE_LINE_PROTO);
2352- virtual ~FilterMultiRangeButton();
2353-
2354- void SetFilter (dash::FilterOption::Ptr filter);
2355- dash::FilterOption::Ptr GetFilter();
2356-
2357- void SetVisualSide(MultiRangeSide side); //0 = left, 1 = center, 2 = right - sucky api i know :(
2358- void SetHasArrow (MultiRangeArrow arrow); //0 = left, 1 = both, 2 = right, -1 = none
2359-
2360- protected:
2361- virtual long ComputeContentSize();
2362- virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
2363- virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
2364- virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
2365-
2366- private:
2367- dash::FilterOption::Ptr filter_;
2368-
2369- void InitTheme ();
2370- void RedrawTheme (nux::Geometry const& geom, cairo_t *cr, nux::ButtonVisualState faked_state);
2371- void OnActivated (nux::Area *area);
2372- void OnActiveChanged(bool value);
2373-
2374- nux::CairoWrapper *prelight_;
2375- nux::CairoWrapper *active_;
2376- nux::CairoWrapper *normal_;
2377- nux::Geometry cached_geometry_;
2378- MultiRangeArrow has_arrow_;
2379- MultiRangeSide side_;
2380-
2381-
2382- };
2383-
2384-}
2385-#endif // FILTERMULTIRANGEBUTTON_H
2386+namespace unity
2387+{
2388+namespace dash
2389+{
2390+
2391+enum class MultiRangeSide
2392+{
2393+ LEFT,
2394+ RIGHT,
2395+ CENTER
2396+};
2397+
2398+enum class MultiRangeArrow
2399+{
2400+ LEFT,
2401+ RIGHT,
2402+ BOTH,
2403+ NONE
2404+};
2405+
2406+class FilterMultiRangeButton : public nux::ToggleButton
2407+{
2408+public:
2409+ FilterMultiRangeButton (std::string const& label, NUX_FILE_LINE_PROTO);
2410+ FilterMultiRangeButton (NUX_FILE_LINE_PROTO);
2411+ ~FilterMultiRangeButton();
2412+
2413+ void SetFilter(FilterOption::Ptr const& filter);
2414+ FilterOption::Ptr GetFilter();
2415+
2416+ void SetVisualSide(MultiRangeSide side); //0 = left, 1 = center, 2 = right - sucky api i know :(
2417+ void SetHasArrow(MultiRangeArrow arrow); //0 = left, 1 = both, 2 = right, -1 = none
2418+
2419+protected:
2420+ virtual long ComputeContentSize();
2421+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
2422+
2423+private:
2424+ void InitTheme();
2425+ void RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state);
2426+ void OnActivated(nux::Area* area);
2427+ void OnActiveChanged(bool value);
2428+
2429+ FilterOption::Ptr filter_;
2430+
2431+ typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr;
2432+
2433+ NuxCairoPtr active_;
2434+ NuxCairoPtr normal_;
2435+ NuxCairoPtr prelight_;
2436+ nux::Geometry cached_geometry_;
2437+ MultiRangeArrow has_arrow_;
2438+ MultiRangeSide side_;
2439+};
2440+
2441+} // namespace dash
2442+} // namespace unity
2443+
2444+#endif // UNITYSHELL_FILTERMULTIRANGEBUTTON_H
2445
2446=== modified file 'plugins/unityshell/src/FilterMultiRangeWidget.cpp'
2447--- plugins/unityshell/src/FilterMultiRangeWidget.cpp 2011-10-11 18:18:13 +0000
2448+++ plugins/unityshell/src/FilterMultiRangeWidget.cpp 2012-01-11 09:37:33 +0000
2449@@ -20,8 +20,6 @@
2450 *
2451 */
2452
2453-#include "config.h"
2454-
2455 #include <Nux/Nux.h>
2456
2457 #include "FilterMultiRangeWidget.h"
2458@@ -31,174 +29,155 @@
2459 #include <glib.h>
2460 #include <glib/gi18n-lib.h>
2461
2462-namespace unity {
2463+namespace unity
2464+{
2465+namespace dash
2466+{
2467
2468 NUX_IMPLEMENT_OBJECT_TYPE(FilterMultiRange);
2469
2470- FilterMultiRange::FilterMultiRange (NUX_FILE_LINE_DECL)
2471- : FilterExpanderLabel (_("Multi-range"), NUX_FILE_LINE_PARAM)
2472- , all_selected (false) {
2473- InitTheme();
2474-
2475- all_button_ = new FilterBasicButton(_("All"), NUX_TRACKER_LOCATION);
2476- all_button_->state_change.connect(sigc::mem_fun(this, &FilterMultiRange::OnAllActivated));
2477- all_button_->SetLabel(_("All"));
2478-
2479- layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
2480- layout_->SetVerticalExternalMargin (12);
2481-
2482- SetRightHandView(all_button_);
2483- SetContents(layout_);
2484- OnActiveChanged(false);
2485- }
2486-
2487- FilterMultiRange::~FilterMultiRange()
2488- {
2489- }
2490-
2491- void FilterMultiRange::SetFilter(dash::Filter::Ptr filter)
2492- {
2493- filter_ = std::static_pointer_cast<dash::MultiRangeFilter>(filter);
2494-
2495- filter_->option_added.connect (sigc::mem_fun (this, &FilterMultiRange::OnOptionAdded));
2496- filter_->option_removed.connect(sigc::mem_fun (this, &FilterMultiRange::OnOptionRemoved));
2497-
2498- // finally - make sure we are up-todate with our filter list
2499- dash::MultiRangeFilter::Options::iterator it;
2500- dash::MultiRangeFilter::Options options = filter_->options;
2501- for (it = options.begin(); it < options.end(); it++)
2502- OnOptionAdded(*it);
2503-
2504- SetLabel(filter_->name);
2505- }
2506-
2507- void FilterMultiRange::OnActiveChanged(bool value)
2508- {
2509- // go through all the buttons, and set the state :(
2510-
2511- std::vector<FilterMultiRangeButton*>::iterator it;
2512- int start = 2000;
2513- int end = 0;
2514- int index = 0;
2515- for ( it=buttons_.begin() ; it < buttons_.end(); it++ )
2516- {
2517- FilterMultiRangeButton* button = (*it);
2518- dash::FilterOption::Ptr filter = button->GetFilter();
2519- bool tmp_active = filter->active;
2520- button->SetActive(tmp_active);
2521- if (filter != NULL)
2522- {
2523- if (filter->active)
2524- {
2525- if (index < start)
2526- start = index;
2527- if (index > end)
2528- end = index;
2529- }
2530- }
2531- index++;
2532- }
2533-
2534- index = 0;
2535- for ( it=buttons_.begin() ; it < buttons_.end(); it++ )
2536- {
2537- FilterMultiRangeButton* button = (*it);
2538-
2539- if (index == start && index == end)
2540- button->SetHasArrow(MultiRangeArrow::MULTI_RANGE_ARROW_BOTH);
2541- else if (index == start)
2542- button->SetHasArrow(MultiRangeArrow::MULTI_RANGE_ARROW_LEFT);
2543- else if (index == end)
2544- button->SetHasArrow(MultiRangeArrow::MULTI_RANGE_ARROW_RIGHT);
2545- else
2546- button->SetHasArrow(MultiRangeArrow::MULTI_RANGE_ARROW_NONE);
2547-
2548- if (index == 0)
2549- button->SetVisualSide(MULTI_RANGE_SIDE_LEFT);
2550- else if (index == (int)buttons_.size() - 1)
2551- button->SetVisualSide(MULTI_RANGE_SIDE_RIGHT);
2552- else
2553- button->SetVisualSide(MULTI_RANGE_CENTER);
2554-
2555- index++;
2556- }
2557- }
2558-
2559- void FilterMultiRange::OnOptionAdded(dash::FilterOption::Ptr new_filter)
2560- {
2561- FilterMultiRangeButton* button = new FilterMultiRangeButton (NUX_TRACKER_LOCATION);
2562- button->SetFilter (new_filter);
2563- layout_->AddView (button, 1);
2564- buttons_.push_back (button);
2565- new_filter->active.changed.connect(sigc::mem_fun (this, &FilterMultiRange::OnActiveChanged));
2566- OnActiveChanged(false);
2567-
2568- }
2569-
2570- void FilterMultiRange::OnOptionRemoved(dash::FilterOption::Ptr removed_filter)
2571- {
2572- std::vector<FilterMultiRangeButton*>::iterator it;
2573- FilterMultiRangeButton* found_filter = NULL;
2574- for ( it=buttons_.begin() ; it < buttons_.end(); it++ )
2575- {
2576- if ((*it)->GetFilter() == removed_filter)
2577- {
2578- found_filter = *it;
2579- break;
2580- }
2581- }
2582-
2583- if (found_filter)
2584+FilterMultiRange::FilterMultiRange(NUX_FILE_LINE_DECL)
2585+ : FilterExpanderLabel(_("Multi-range"), NUX_FILE_LINE_PARAM)
2586+{
2587+ InitTheme();
2588+
2589+ all_button_ = new FilterAllButton(NUX_TRACKER_LOCATION);
2590+
2591+ layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
2592+ layout_->SetVerticalExternalMargin(12);
2593+
2594+ SetRightHandView(all_button_);
2595+ SetContents(layout_);
2596+ OnActiveChanged(false);
2597+}
2598+
2599+FilterMultiRange::~FilterMultiRange()
2600+{
2601+}
2602+
2603+void FilterMultiRange::SetFilter(Filter::Ptr const& filter)
2604+{
2605+ filter_ = std::static_pointer_cast<MultiRangeFilter>(filter);
2606+
2607+ all_button_->SetFilter(filter_);
2608+ expanded = !filter_->collapsed();
2609+
2610+ filter_->option_added.connect(sigc::mem_fun(this, &FilterMultiRange::OnOptionAdded));
2611+ filter_->option_removed.connect(sigc::mem_fun(this, &FilterMultiRange::OnOptionRemoved));
2612+
2613+ // finally - make sure we are up-todate with our filter list
2614+ for (auto it : filter_->options())
2615+ OnOptionAdded(it);
2616+
2617+ SetLabel(filter_->name);
2618+}
2619+
2620+void FilterMultiRange::OnActiveChanged(bool value)
2621+{
2622+ // go through all the buttons, and set the state :(
2623+ int start = 2000;
2624+ int end = 0;
2625+ int index = 0;
2626+ for (auto button : buttons_)
2627+ {
2628+ FilterOption::Ptr filter = button->GetFilter();
2629+ bool tmp_active = filter->active;
2630+ button->SetActive(tmp_active);
2631+ if (filter != nullptr)
2632+ {
2633+ if (filter->active)
2634+ {
2635+ if (index < start)
2636+ start = index;
2637+ if (index > end)
2638+ end = index;
2639+ }
2640+ }
2641+ index++;
2642+ }
2643+
2644+ index = 0;
2645+ for (auto button : buttons_)
2646+ {
2647+ if (index == start && index == end)
2648+ button->SetHasArrow(MultiRangeArrow::BOTH);
2649+ else if (index == start)
2650+ button->SetHasArrow(MultiRangeArrow::LEFT);
2651+ else if (index == end)
2652+ button->SetHasArrow(MultiRangeArrow::RIGHT);
2653+ else
2654+ button->SetHasArrow(MultiRangeArrow::NONE);
2655+
2656+ if (index == 0)
2657+ button->SetVisualSide(MultiRangeSide::LEFT);
2658+ else if (index == (int)buttons_.size() - 1)
2659+ button->SetVisualSide(MultiRangeSide::RIGHT);
2660+ else
2661+ button->SetVisualSide(MultiRangeSide::CENTER);
2662+
2663+ index++;
2664+ }
2665+}
2666+
2667+void FilterMultiRange::OnOptionAdded(FilterOption::Ptr const& new_filter)
2668+{
2669+ FilterMultiRangeButton* button = new FilterMultiRangeButton(NUX_TRACKER_LOCATION);
2670+ button->SetFilter(new_filter);
2671+ layout_->AddView(button);
2672+ buttons_.push_back(button);
2673+ new_filter->active.changed.connect(sigc::mem_fun(this, &FilterMultiRange::OnActiveChanged));
2674+ OnActiveChanged(false);
2675+
2676+}
2677+
2678+void FilterMultiRange::OnOptionRemoved(FilterOption::Ptr const& removed_filter)
2679+{
2680+ for (auto it=buttons_.begin() ; it != buttons_.end(); it++)
2681+ {
2682+ if ((*it)->GetFilter() == removed_filter)
2683 {
2684 layout_->RemoveChildObject(*it);
2685 buttons_.erase(it);
2686+ break;
2687 }
2688-
2689- OnActiveChanged(false);
2690- }
2691-
2692- std::string FilterMultiRange::GetFilterType ()
2693- {
2694- return "FilterMultiRange";
2695- }
2696-
2697- void FilterMultiRange::InitTheme()
2698- {
2699- //FIXME - build theme here - store images, cache them, fun fun fun
2700- }
2701-
2702- void FilterMultiRange::OnAllActivated(nux::View *view)
2703- {
2704- if (filter_)
2705- filter_->Clear();
2706- }
2707-
2708- void FilterMultiRange::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
2709- nux::Geometry geo = GetGeometry();
2710- nux::Color col(0.2f, 0.2f, 0.2f, 0.2f);
2711-
2712- GfxContext.PushClippingRectangle(geo);
2713- nux::GetPainter().PaintBackground(GfxContext, geo);
2714-
2715- nux::GetPainter().Draw2DLine(GfxContext,
2716- geo.x, geo.y + geo.height - 1,
2717- geo.x + geo.width, geo.y + geo.height - 1,
2718- col,
2719- col);
2720-
2721- GfxContext.PopClippingRectangle();
2722- }
2723-
2724- void FilterMultiRange::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
2725- GfxContext.PushClippingRectangle(GetGeometry());
2726-
2727- GetLayout()->ProcessDraw(GfxContext, force_draw);
2728-
2729- GfxContext.PopClippingRectangle();
2730- }
2731-
2732- void FilterMultiRange::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
2733- nux::View::PostDraw(GfxContext, force_draw);
2734- }
2735-
2736-};
2737+ }
2738+
2739+ OnActiveChanged(false);
2740+}
2741+
2742+std::string FilterMultiRange::GetFilterType()
2743+{
2744+ return "FilterMultiRange";
2745+}
2746+
2747+void FilterMultiRange::InitTheme()
2748+{
2749+ //FIXME - build theme here - store images, cache them, fun fun fun
2750+}
2751+
2752+void FilterMultiRange::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
2753+{
2754+ nux::Geometry const& geo = GetGeometry();
2755+ nux::Color col(0.2f, 0.2f, 0.2f, 0.2f);
2756+
2757+ GfxContext.PushClippingRectangle(geo);
2758+ nux::GetPainter().PaintBackground(GfxContext, geo);
2759+
2760+ nux::GetPainter().Draw2DLine(GfxContext,
2761+ geo.x, geo.y + geo.height - 1,
2762+ geo.x + geo.width, geo.y + geo.height - 1,
2763+ col,
2764+ col);
2765+
2766+ GfxContext.PopClippingRectangle();
2767+}
2768+
2769+void FilterMultiRange::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
2770+{
2771+ GfxContext.PushClippingRectangle(GetGeometry());
2772+ GetLayout()->ProcessDraw(GfxContext, force_draw);
2773+ GfxContext.PopClippingRectangle();
2774+}
2775+
2776+} // namespace dash
2777+} // namespace unity
2778
2779=== modified file 'plugins/unityshell/src/FilterMultiRangeWidget.h'
2780--- plugins/unityshell/src/FilterMultiRangeWidget.h 2011-10-11 18:18:13 +0000
2781+++ plugins/unityshell/src/FilterMultiRangeWidget.h 2012-01-11 09:37:33 +0000
2782@@ -20,55 +20,55 @@
2783 *
2784 */
2785
2786-
2787-
2788-#ifndef FILTERMULTIRANGE_H
2789-#define FILTERMULTIRANGE_H
2790+#ifndef UNITYSHELL_FILTERMULTIRANGE_H
2791+#define UNITYSHELL_FILTERMULTIRANGE_H
2792
2793 #include <Nux/Nux.h>
2794 #include <Nux/HLayout.h>
2795 #include <Nux/VLayout.h>
2796 #include <UnityCore/MultiRangeFilter.h>
2797
2798-#include "FilterWidget.h"
2799+#include "FilterAllButton.h"
2800 #include "FilterBasicButton.h"
2801 #include "FilterExpanderLabel.h"
2802
2803-namespace unity {
2804- class FilterMultiRangeButton;
2805-
2806- class FilterMultiRange : public FilterExpanderLabel, public FilterWidget
2807- {
2808- NUX_DECLARE_OBJECT_TYPE(FilterMultiRange, FilterExpanderLabel);
2809- public:
2810- FilterMultiRange (NUX_FILE_LINE_PROTO);
2811- virtual ~FilterMultiRange();
2812-
2813- void SetFilter (dash::Filter::Ptr filter);
2814- std::string GetFilterType ();
2815-
2816- nux::Property<bool> all_selected;
2817-
2818- protected:
2819- virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
2820- virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
2821- virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
2822-
2823- void InitTheme ();
2824-
2825- private:
2826- void OnAllActivated(nux::View* view);
2827- void OnOptionAdded(dash::FilterOption::Ptr new_filter);
2828- void OnOptionRemoved(dash::FilterOption::Ptr removed_filter);
2829- void OnActiveChanged(bool value);
2830-
2831- nux::HLayout *layout_;
2832- FilterBasicButton* all_button_;
2833-
2834- std::vector<FilterMultiRangeButton*> buttons_;
2835- dash::MultiRangeFilter::Ptr filter_;
2836- };
2837-
2838-}
2839-
2840-#endif // FILTERMULTIRANGE_H
2841+namespace unity
2842+{
2843+namespace dash
2844+{
2845+
2846+class FilterMultiRangeButton;
2847+
2848+class FilterMultiRange : public FilterExpanderLabel
2849+{
2850+ NUX_DECLARE_OBJECT_TYPE(FilterMultiRange, FilterExpanderLabel);
2851+public:
2852+ FilterMultiRange(NUX_FILE_LINE_PROTO);
2853+ virtual ~FilterMultiRange();
2854+
2855+ void SetFilter(Filter::Ptr const& filter);
2856+ std::string GetFilterType();
2857+
2858+protected:
2859+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
2860+ virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
2861+
2862+ void InitTheme();
2863+
2864+private:
2865+ void OnAllActivated(nux::View* view);
2866+ void OnOptionAdded(dash::FilterOption::Ptr const& new_filter);
2867+ void OnOptionRemoved(dash::FilterOption::Ptr const& removed_filter);
2868+ void OnActiveChanged(bool value);
2869+
2870+ nux::HLayout* layout_;
2871+ FilterAllButton* all_button_;
2872+
2873+ std::vector<FilterMultiRangeButton*> buttons_;
2874+ MultiRangeFilter::Ptr filter_;
2875+};
2876+
2877+} // unityshell dash
2878+} // unityshell unity
2879+
2880+#endif // UNITYSHELL_FILTERMULTIRANGE_H
2881
2882=== modified file 'plugins/unityshell/src/FilterRatingsButton.cpp'
2883--- plugins/unityshell/src/FilterRatingsButton.cpp 2011-11-08 19:41:00 +0000
2884+++ plugins/unityshell/src/FilterRatingsButton.cpp 2012-01-11 09:37:33 +0000
2885@@ -19,8 +19,6 @@
2886 *
2887 */
2888
2889-#include "config.h"
2890-
2891 #include <math.h>
2892
2893 #include <Nux/Nux.h>
2894@@ -29,237 +27,218 @@
2895 #include "DashStyle.h"
2896 #include "FilterRatingsButton.h"
2897
2898-namespace {
2899- nux::logging::Logger logger("unity.dash.FilterRatingsButton");
2900-}
2901-
2902-namespace unity {
2903-
2904- FilterRatingsButton::FilterRatingsButton (NUX_FILE_LINE_DECL)
2905- : nux::Button (NUX_FILE_LINE_PARAM)
2906- , prelight_empty_ (NULL)
2907- , active_empty_ (NULL)
2908- , normal_empty_ (NULL)
2909- , prelight_half_ (NULL)
2910- , active_half_ (NULL)
2911- , normal_half_ (NULL)
2912- , prelight_full_ (NULL)
2913- , active_full_ (NULL)
2914- , normal_full_ (NULL)
2915- {
2916- InitTheme();
2917-
2918- mouse_up.connect (sigc::mem_fun (this, &FilterRatingsButton::RecvMouseUp) );
2919- mouse_drag.connect (sigc::mem_fun (this, &FilterRatingsButton::RecvMouseDrag) );
2920- }
2921-
2922- FilterRatingsButton::~FilterRatingsButton() {
2923- delete prelight_empty_;
2924- delete active_empty_;
2925- delete normal_empty_;
2926- delete prelight_half_;
2927- delete active_half_;
2928- delete normal_half_;
2929- delete prelight_full_;
2930- delete active_full_ ;
2931- delete normal_full_;
2932- }
2933-
2934- void FilterRatingsButton::SetFilter(dash::Filter::Ptr filter)
2935- {
2936- filter_ = std::static_pointer_cast<dash::RatingsFilter>(filter);
2937- filter_->rating.changed.connect (sigc::mem_fun (this, &FilterRatingsButton::OnRatingsChanged));
2938- NeedRedraw();
2939- }
2940-
2941- std::string FilterRatingsButton::GetFilterType ()
2942- {
2943- return "FilterRatingsButton";
2944- }
2945-
2946- void FilterRatingsButton::InitTheme()
2947- {
2948- if (prelight_empty_ == NULL)
2949- {
2950- nux::Geometry geometry = GetGeometry();
2951- geometry.width /= 5;
2952- prelight_empty_ = new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 0, nux::ButtonVisualState::VISUAL_STATE_PRELIGHT));
2953- active_empty_ = new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 0, nux::ButtonVisualState::VISUAL_STATE_PRESSED));
2954- normal_empty_ = new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 0, nux::ButtonVisualState::VISUAL_STATE_NORMAL));
2955-
2956- prelight_half_ = new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 1, nux::ButtonVisualState::VISUAL_STATE_PRELIGHT));
2957- active_half_ = new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 1, nux::ButtonVisualState::VISUAL_STATE_PRESSED));
2958- normal_half_ = new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 1, nux::ButtonVisualState::VISUAL_STATE_NORMAL));
2959-
2960- prelight_full_ = new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 2, nux::ButtonVisualState::VISUAL_STATE_PRELIGHT));
2961- active_full_ = new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 2, nux::ButtonVisualState::VISUAL_STATE_PRESSED));
2962- normal_full_ = new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 2, nux::ButtonVisualState::VISUAL_STATE_NORMAL));
2963- }
2964- }
2965-
2966- void FilterRatingsButton::RedrawTheme (nux::Geometry const& geom, cairo_t *cr, int type, nux::ButtonVisualState faked_state)
2967- {
2968- dash::Style& dash_style = dash::Style::Instance();
2969- if (type == 0)
2970- {
2971- // empty
2972- dash_style.StarEmpty (cr, faked_state);
2973- }
2974- else if (type == 1)
2975- {
2976- // half
2977- dash_style.StarHalf (cr, faked_state);
2978+namespace unity
2979+{
2980+namespace dash
2981+{
2982+
2983+FilterRatingsButton::FilterRatingsButton(NUX_FILE_LINE_DECL)
2984+ : nux::ToggleButton(NUX_FILE_LINE_PARAM)
2985+{
2986+ InitTheme();
2987+
2988+ mouse_up.connect(sigc::mem_fun(this, &FilterRatingsButton::RecvMouseUp));
2989+ mouse_drag.connect(sigc::mem_fun(this, &FilterRatingsButton::RecvMouseDrag));
2990+}
2991+
2992+FilterRatingsButton::~FilterRatingsButton()
2993+{
2994+}
2995+
2996+void FilterRatingsButton::SetFilter(Filter::Ptr const& filter)
2997+{
2998+ filter_ = std::static_pointer_cast<RatingsFilter>(filter);
2999+ filter_->rating.changed.connect(sigc::mem_fun(this, &FilterRatingsButton::OnRatingsChanged));
3000+ NeedRedraw();
3001+}
3002+
3003+std::string FilterRatingsButton::GetFilterType()
3004+{
3005+ return "FilterRatingsButton";
3006+}
3007+
3008+void FilterRatingsButton::InitTheme()
3009+{
3010+ if (!active_empty_)
3011+ {
3012+ nux::Geometry geometry(GetGeometry());
3013+ geometry.width /= 5;
3014+
3015+ active_empty_.reset(new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 0, nux::ButtonVisualState::VISUAL_STATE_PRESSED)));
3016+ normal_empty_.reset(new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 0, nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
3017+ prelight_empty_.reset(new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 0, nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
3018+
3019+ active_half_.reset(new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 1, nux::ButtonVisualState::VISUAL_STATE_PRESSED)));
3020+ normal_half_.reset(new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 1, nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
3021+ prelight_half_.reset(new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 1, nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
3022+
3023+ active_full_.reset(new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 2, nux::ButtonVisualState::VISUAL_STATE_PRESSED)));
3024+ normal_full_.reset(new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 2, nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
3025+ prelight_full_.reset(new nux::CairoWrapper(geometry, sigc::bind(sigc::mem_fun(this, &FilterRatingsButton::RedrawTheme), 2, nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
3026+ }
3027+}
3028+
3029+void FilterRatingsButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, int type, nux::ButtonVisualState faked_state)
3030+{
3031+ Style& dash_style = Style::Instance();
3032+ if (type == 0)
3033+ {
3034+ // empty
3035+ dash_style.StarEmpty(cr, faked_state);
3036+ }
3037+ else if (type == 1)
3038+ {
3039+ // half
3040+ dash_style.StarHalf(cr, faked_state);
3041+ }
3042+ else
3043+ {
3044+ // full
3045+ dash_style.StarFull(cr, faked_state);
3046+ }
3047+}
3048+
3049+long FilterRatingsButton::ComputeContentSize()
3050+{
3051+ long ret = nux::Button::ComputeContentSize();
3052+ nux::Geometry geo(GetGeometry());
3053+
3054+ if (cached_geometry_ != geo)
3055+ {
3056+ geo.width = 27;
3057+ active_empty_->Invalidate(geo);
3058+ normal_empty_->Invalidate(geo);
3059+ prelight_empty_->Invalidate(geo);
3060+
3061+ active_half_->Invalidate(geo);
3062+ normal_half_->Invalidate(geo);
3063+ prelight_half_->Invalidate(geo);
3064+
3065+ active_full_->Invalidate(geo);
3066+ normal_full_->Invalidate(geo);
3067+ prelight_full_->Invalidate(geo);
3068+
3069+ cached_geometry_ = geo;
3070+ }
3071+
3072+ return ret;
3073+}
3074+
3075+void FilterRatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
3076+{
3077+ int rating = 0;
3078+ if (filter_ && filter_->filtering)
3079+ rating = static_cast<int>(filter_->rating * 5);
3080+ // FIXME: 9/26/2011
3081+ // We should probably support an API for saying whether the ratings
3082+ // should or shouldn't support half stars...but our only consumer at
3083+ // the moment is the applications lens which according to design
3084+ // (Bug #839759) shouldn't. So for now just force rounding.
3085+ // int total_half_stars = rating % 2;
3086+ // int total_full_stars = rating / 2;
3087+ int total_full_stars = rating;
3088+ int total_half_stars = 0;
3089+
3090+ nux::Geometry const& geo = GetGeometry();
3091+ nux::Geometry geo_star(geo);
3092+ geo_star.width = 27;
3093+
3094+ gPainter.PaintBackground(GfxContext, geo);
3095+ // set up our texture mode
3096+ nux::TexCoordXForm texxform;
3097+ texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
3098+ texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
3099+
3100+ // clear what is behind us
3101+ unsigned int alpha = 0, src = 0, dest = 0;
3102+
3103+ GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
3104+ GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
3105+
3106+ nux::Color col = nux::color::Black;
3107+ col.alpha = 0;
3108+ GfxContext.QRP_Color(geo.x,
3109+ geo.y,
3110+ geo.width,
3111+ geo.height,
3112+ col);
3113+
3114+ for (int index = 0; index < 5; index++)
3115+ {
3116+ nux::BaseTexture* texture = normal_empty_->GetTexture();
3117+ if (index < total_full_stars)
3118+ {
3119+ if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
3120+ texture = normal_full_->GetTexture();
3121+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
3122+ texture = prelight_full_->GetTexture();
3123+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
3124+ texture = active_full_->GetTexture();
3125+ }
3126+ else if (index < total_full_stars + total_half_stars)
3127+ {
3128+ if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
3129+ texture = normal_half_->GetTexture();
3130+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
3131+ texture = prelight_half_->GetTexture();
3132+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
3133+ texture = active_half_->GetTexture();
3134 }
3135 else
3136 {
3137- // full
3138- dash_style.StarFull (cr, faked_state);
3139- }
3140- }
3141-
3142- long FilterRatingsButton::ComputeContentSize ()
3143- {
3144- long ret = nux::Button::ComputeContentSize();
3145- if (cached_geometry_ != GetGeometry())
3146- {
3147- nux::Geometry geometry = GetGeometry();
3148- //geometry.width /= 5;
3149- geometry.width = 27;
3150- prelight_empty_->Invalidate(geometry);
3151- active_empty_->Invalidate(geometry);
3152- normal_empty_->Invalidate(geometry);
3153-
3154- prelight_half_->Invalidate(geometry);
3155- active_half_->Invalidate(geometry);
3156- normal_half_->Invalidate(geometry);
3157-
3158- prelight_full_->Invalidate(geometry);
3159- active_full_->Invalidate(geometry);
3160- normal_full_->Invalidate(geometry);
3161- }
3162-
3163- cached_geometry_ = GetGeometry();
3164- return ret;
3165- }
3166-
3167- void FilterRatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
3168- int rating = 0;
3169- if (filter_ != NULL && filter_->filtering)
3170- rating = static_cast<int>(filter_->rating * 5);
3171- // FIXME: 9/26/2011
3172- // We should probably support an API for saying whether the ratings
3173- // should or shouldn't support half stars...but our only consumer at
3174- // the moment is the applications lens which according to design
3175- // (Bug #839759) shouldn't. So for now just force rounding.
3176- // int total_half_stars = rating % 2;
3177- // int total_full_stars = rating / 2;
3178- int total_full_stars = rating;
3179- int total_half_stars = 0;
3180-
3181- nux::Geometry geometry = GetGeometry ();
3182- //geometry.width = geometry.width / 5;
3183- geometry.width = 27;
3184-
3185- gPainter.PaintBackground(GfxContext, GetGeometry());
3186- // set up our texture mode
3187- nux::TexCoordXForm texxform;
3188- texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
3189- texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
3190-
3191- // clear what is behind us
3192- unsigned int alpha = 0, src = 0, dest = 0;
3193-
3194- GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
3195- GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
3196-
3197- nux::Color col = nux::color::Black;
3198- col.alpha = 0;
3199- GfxContext.QRP_Color(GetGeometry().x,
3200- GetGeometry().y,
3201- GetGeometry().width,
3202- GetGeometry().height,
3203- col);
3204-
3205- for (int index = 0; index < 5; index++)
3206- {
3207- nux::BaseTexture *texture = normal_empty_->GetTexture();
3208-
3209- if (index < total_full_stars) {
3210- if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
3211- texture = normal_full_->GetTexture();
3212- else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
3213- texture = prelight_full_->GetTexture();
3214- else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
3215- texture = active_full_->GetTexture();
3216- }
3217- else if (index < total_full_stars + total_half_stars) {
3218- if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
3219- texture = normal_half_->GetTexture();
3220- else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
3221- texture = prelight_half_->GetTexture();
3222- else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
3223- texture = active_half_->GetTexture();
3224- }
3225- else {
3226- if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
3227- texture = normal_empty_->GetTexture();
3228- else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
3229- texture = prelight_empty_->GetTexture();
3230- else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
3231- texture = active_empty_->GetTexture();
3232- }
3233-
3234- GfxContext.QRP_1Tex(geometry.x,
3235- geometry.y,
3236- geometry.width,
3237- geometry.height,
3238- texture->GetDeviceTexture(),
3239- texxform,
3240- nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
3241-
3242- geometry.x += geometry.width + 10;
3243-
3244- }
3245-
3246- GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
3247-
3248- }
3249-
3250- void FilterRatingsButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
3251- nux::Button::DrawContent(GfxContext, force_draw);
3252- }
3253-
3254- void FilterRatingsButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
3255- nux::Button::PostDraw(GfxContext, force_draw);
3256- }
3257-
3258- static void _UpdateRatingToMouse (dash::RatingsFilter::Ptr filter, int x)
3259- {
3260- int width = 180;
3261- float new_rating = (static_cast<float>(x) / width);
3262-
3263- // FIXME: change to 10 once we decide to support also half-stars
3264- new_rating = ceil(5*new_rating)/5;
3265- new_rating = new_rating > 1 ? 1 : (new_rating < 0 ? 0 : new_rating);
3266-
3267- if (filter != NULL)
3268- filter->rating = new_rating;
3269- }
3270-
3271- void FilterRatingsButton::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
3272- {
3273- _UpdateRatingToMouse (filter_, x);
3274- }
3275-
3276- void FilterRatingsButton::RecvMouseDrag (int x, int y, int dx, int dy,
3277- unsigned long button_flags,
3278- unsigned long key_flags)
3279- {
3280- _UpdateRatingToMouse (filter_, x);
3281- }
3282-
3283- void FilterRatingsButton::OnRatingsChanged (int rating) {
3284- NeedRedraw();
3285- }
3286-
3287-};
3288+ if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
3289+ texture = normal_empty_->GetTexture();
3290+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
3291+ texture = prelight_empty_->GetTexture();
3292+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
3293+ texture = active_empty_->GetTexture();
3294+ }
3295+
3296+ GfxContext.QRP_1Tex(geo_star.x,
3297+ geo_star.y,
3298+ geo_star.width,
3299+ geo_star.height,
3300+ texture->GetDeviceTexture(),
3301+ texxform,
3302+ nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
3303+
3304+ geo_star.x += geo_star.width + 10;
3305+
3306+ }
3307+
3308+ GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
3309+
3310+}
3311+
3312+static void _UpdateRatingToMouse(RatingsFilter::Ptr filter, int x)
3313+{
3314+ int width = 180;
3315+ float new_rating = (static_cast<float>(x) / width);
3316+
3317+ // FIXME: change to 10 once we decide to support also half-stars
3318+ new_rating = ceil(5 * new_rating) / 5;
3319+ new_rating = (new_rating > 1) ? 1 : ((new_rating < 0) ? 0 : new_rating);
3320+
3321+ if (filter)
3322+ filter->rating = new_rating;
3323+}
3324+
3325+void FilterRatingsButton::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags)
3326+{
3327+ _UpdateRatingToMouse(filter_, x);
3328+}
3329+
3330+void FilterRatingsButton::RecvMouseDrag(int x, int y, int dx, int dy,
3331+ unsigned long button_flags,
3332+ unsigned long key_flags)
3333+{
3334+ _UpdateRatingToMouse(filter_, x);
3335+}
3336+
3337+void FilterRatingsButton::OnRatingsChanged(int rating)
3338+{
3339+ NeedRedraw();
3340+}
3341+
3342+} // namespace dash
3343+} // namespace unity
3344
3345=== modified file 'plugins/unityshell/src/FilterRatingsButton.h'
3346--- plugins/unityshell/src/FilterRatingsButton.h 2011-10-11 18:18:13 +0000
3347+++ plugins/unityshell/src/FilterRatingsButton.h 2012-01-11 09:37:33 +0000
3348@@ -19,59 +19,61 @@
3349 *
3350 */
3351
3352-
3353-
3354-#ifndef FILTERRATINGSBUTTONWIDGET_H
3355-#define FILTERRATINGSBUTTONWIDGET_H
3356+#ifndef UNITYSHELL_FILTERRATINGSBUTTONWIDGET_H
3357+#define UNITYSHELL_FILTERRATINGSBUTTONWIDGET_H
3358+
3359+#include <memory>
3360
3361 #include <Nux/Nux.h>
3362-#include <Nux/Button.h>
3363+#include <Nux/ToggleButton.h>
3364 #include <Nux/CairoWrapper.h>
3365 #include <UnityCore/RatingsFilter.h>
3366
3367-#include "FilterWidget.h"
3368-
3369-namespace unity {
3370-
3371- class FilterRatingsButton : public nux::Button, public unity::FilterWidget {
3372- public:
3373- FilterRatingsButton (NUX_FILE_LINE_PROTO);
3374- virtual ~FilterRatingsButton();
3375-
3376- void SetFilter (dash::Filter::Ptr filter);
3377- dash::RatingsFilter::Ptr GetFilter ();
3378- std::string GetFilterType ();
3379-
3380- protected:
3381- virtual long ComputeContentSize ();
3382- virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
3383- virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
3384- virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
3385-
3386- void InitTheme ();
3387-
3388- //void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
3389- void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
3390- void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
3391- void OnRatingsChanged (int rating);
3392-
3393- nux::CairoWrapper *prelight_empty_;
3394- nux::CairoWrapper *active_empty_;
3395- nux::CairoWrapper *normal_empty_;
3396- nux::CairoWrapper *prelight_half_;
3397- nux::CairoWrapper *active_half_;
3398- nux::CairoWrapper *normal_half_;
3399- nux::CairoWrapper *prelight_full_;
3400- nux::CairoWrapper *active_full_;
3401- nux::CairoWrapper *normal_full_;
3402- nux::Geometry cached_geometry_;
3403-
3404- void RedrawTheme (nux::Geometry const& geom, cairo_t *cr, int type, nux::ButtonVisualState faked_state);
3405-
3406- dash::RatingsFilter::Ptr filter_;
3407-
3408- };
3409-
3410-}
3411-
3412-#endif // FILTERRATINGSBUTTONWIDGET_H
3413+namespace unity
3414+{
3415+namespace dash
3416+{
3417+
3418+class FilterRatingsButton : public nux::ToggleButton
3419+{
3420+public:
3421+ FilterRatingsButton(NUX_FILE_LINE_PROTO);
3422+ virtual ~FilterRatingsButton();
3423+
3424+ void SetFilter(Filter::Ptr const& filter);
3425+ RatingsFilter::Ptr GetFilter();
3426+ std::string GetFilterType();
3427+
3428+protected:
3429+ virtual long ComputeContentSize();
3430+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
3431+
3432+ void InitTheme();
3433+ void RedrawTheme(nux::Geometry const& geom, cairo_t* cr, int type, nux::ButtonVisualState faked_state);
3434+
3435+ void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
3436+ void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
3437+ void OnRatingsChanged(int rating);
3438+
3439+ typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr;
3440+
3441+ NuxCairoPtr active_empty_;
3442+ NuxCairoPtr normal_empty_;
3443+ NuxCairoPtr prelight_empty_;
3444+ NuxCairoPtr active_half_;
3445+ NuxCairoPtr normal_half_;
3446+ NuxCairoPtr prelight_half_;
3447+ NuxCairoPtr active_full_;
3448+ NuxCairoPtr normal_full_;
3449+ NuxCairoPtr prelight_full_;
3450+ nux::Geometry cached_geometry_;
3451+
3452+ dash::RatingsFilter::Ptr filter_;
3453+
3454+};
3455+
3456+} // namespace dash
3457+} // namespace unity
3458+
3459+#endif // UNITYSHELL_FILTERRATINGSBUTTONWIDGET_H
3460+
3461
3462=== modified file 'plugins/unityshell/src/FilterRatingsWidget.cpp'
3463--- plugins/unityshell/src/FilterRatingsWidget.cpp 2011-10-11 18:18:13 +0000
3464+++ plugins/unityshell/src/FilterRatingsWidget.cpp 2012-01-11 09:37:33 +0000
3465@@ -20,8 +20,6 @@
3466 *
3467 */
3468
3469-#include "config.h"
3470-
3471 #include <Nux/Nux.h>
3472 #include <glib.h>
3473 #include <glib/gi18n-lib.h>
3474@@ -32,92 +30,64 @@
3475 #include "FilterRatingsButton.h"
3476 #include "FilterRatingsWidget.h"
3477
3478-
3479-namespace unity {
3480+namespace unity
3481+{
3482+namespace dash
3483+{
3484
3485 NUX_IMPLEMENT_OBJECT_TYPE(FilterRatingsWidget);
3486
3487- FilterRatingsWidget::FilterRatingsWidget (NUX_FILE_LINE_DECL)
3488- : FilterExpanderLabel (_("Rating"), NUX_FILE_LINE_PARAM),
3489- last_rating_ (0.0f)
3490- {
3491- any_button_ = new FilterBasicButton(_("All"), NUX_TRACKER_LOCATION);
3492- any_button_->state_change.connect(sigc::mem_fun(this, &FilterRatingsWidget::OnAnyButtonActivated));
3493- any_button_->SetLabel(_("All"));
3494-
3495- SetRightHandView(any_button_);
3496-
3497- nux::VLayout* layout = new nux::VLayout (NUX_TRACKER_LOCATION);
3498- ratings_ = new FilterRatingsButton (NUX_TRACKER_LOCATION);
3499-
3500- layout->AddView(ratings_);
3501- SetContents(layout);
3502- }
3503-
3504- FilterRatingsWidget::~FilterRatingsWidget()
3505- {
3506- }
3507-
3508- void FilterRatingsWidget::OnAnyButtonActivated(nux::View *view)
3509- {
3510- if (any_button_->Active())
3511- {
3512- last_rating_ = filter_->rating;
3513- // we need to make sure the property changes, otherwise there'll be no
3514- // signals, so we'll set it to 0.0f
3515- filter_->rating = 0.0f;
3516- filter_->Clear();
3517- }
3518- else
3519- {
3520- filter_->rating = last_rating_;
3521- }
3522- }
3523-
3524- void FilterRatingsWidget::OnFilterRatingChanged(float new_rating)
3525- {
3526- if (new_rating <= 0.0f)
3527- {
3528- any_button_->SetActive(true);
3529- }
3530- else
3531- {
3532- any_button_->SetActive(false);
3533- }
3534- }
3535-
3536- void FilterRatingsWidget::SetFilter (dash::Filter::Ptr filter)
3537- {
3538- filter_ = std::static_pointer_cast<dash::RatingsFilter>(filter);
3539- filter_->rating.changed.connect (sigc::mem_fun (this, &FilterRatingsWidget::OnFilterRatingChanged));
3540- ratings_->SetFilter(filter);
3541- SetLabel(filter_->name);
3542- NeedRedraw();
3543- }
3544-
3545- std::string FilterRatingsWidget::GetFilterType ()
3546- {
3547- return "FilterRatingsWidget";
3548- }
3549-
3550- void FilterRatingsWidget::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
3551- nux::Geometry geo = GetGeometry();
3552-
3553- GfxContext.PushClippingRectangle(geo);
3554- nux::GetPainter().PaintBackground(GfxContext, geo);
3555- GfxContext.PopClippingRectangle();
3556- }
3557-
3558- void FilterRatingsWidget::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
3559- GfxContext.PushClippingRectangle(GetGeometry());
3560-
3561- GetLayout()->ProcessDraw(GfxContext, force_draw);
3562-
3563- GfxContext.PopClippingRectangle();
3564- }
3565-
3566- void FilterRatingsWidget::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
3567- nux::View::PostDraw(GfxContext, force_draw);
3568- }
3569-
3570-};
3571+FilterRatingsWidget::FilterRatingsWidget(NUX_FILE_LINE_DECL)
3572+ : FilterExpanderLabel(_("Rating"), NUX_FILE_LINE_PARAM)
3573+{
3574+ all_button_ = new FilterAllButton(NUX_TRACKER_LOCATION);
3575+
3576+ nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION);
3577+ layout->SetTopAndBottomPadding(10, 0);
3578+ ratings_ = new FilterRatingsButton(NUX_TRACKER_LOCATION);
3579+
3580+ layout->AddView(ratings_);
3581+
3582+ SetRightHandView(all_button_);
3583+ SetContents(layout);
3584+}
3585+
3586+FilterRatingsWidget::~FilterRatingsWidget()
3587+{
3588+}
3589+
3590+void FilterRatingsWidget::SetFilter(Filter::Ptr const& filter)
3591+{
3592+ filter_ = std::static_pointer_cast<RatingsFilter>(filter);
3593+
3594+ all_button_->SetFilter(filter_);
3595+ expanded = !filter_->collapsed();
3596+ ratings_->SetFilter(filter_);
3597+
3598+ SetLabel(filter_->name);
3599+ NeedRedraw();
3600+}
3601+
3602+std::string FilterRatingsWidget::GetFilterType()
3603+{
3604+ return "FilterRatingsWidget";
3605+}
3606+
3607+void FilterRatingsWidget::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
3608+{
3609+ nux::Geometry const& geo = GetGeometry();
3610+
3611+ GfxContext.PushClippingRectangle(geo);
3612+ nux::GetPainter().PaintBackground(GfxContext, geo);
3613+ GfxContext.PopClippingRectangle();
3614+}
3615+
3616+void FilterRatingsWidget::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
3617+{
3618+ GfxContext.PushClippingRectangle(GetGeometry());
3619+ GetLayout()->ProcessDraw(GfxContext, force_draw);
3620+ GfxContext.PopClippingRectangle();
3621+}
3622+
3623+} // namespace dash
3624+} // namespace unity
3625
3626=== modified file 'plugins/unityshell/src/FilterRatingsWidget.h'
3627--- plugins/unityshell/src/FilterRatingsWidget.h 2011-10-11 18:18:13 +0000
3628+++ plugins/unityshell/src/FilterRatingsWidget.h 2012-01-11 09:37:33 +0000
3629@@ -20,10 +20,8 @@
3630 *
3631 */
3632
3633-
3634-
3635-#ifndef FILTERRATINGSWIDGET_H
3636-#define FILTERRATINGSWIDGET_H
3637+#ifndef UNITYSHELL_FILTERRATINGSWIDGET_H
3638+#define UNITYSHELL_FILTERRATINGSWIDGET_H
3639
3640 #include <Nux/Nux.h>
3641 #include <Nux/GridHLayout.h>
3642@@ -31,42 +29,37 @@
3643 #include <Nux/VLayout.h>
3644 #include <UnityCore/RatingsFilter.h>
3645
3646-#include "FilterWidget.h"
3647+#include "FilterAllButton.h"
3648 #include "FilterExpanderLabel.h"
3649
3650-namespace unity {
3651- class FilterBasicButton;
3652- class FilterRatingsButton;
3653-
3654- class FilterRatingsWidget : public FilterExpanderLabel, public FilterWidget
3655- {
3656- NUX_DECLARE_OBJECT_TYPE(FilterRatingsWidget, FilterExpanderLabel);
3657- public:
3658- FilterRatingsWidget (NUX_FILE_LINE_PROTO);
3659- virtual ~FilterRatingsWidget();
3660-
3661- void SetFilter (dash::Filter::Ptr filter);
3662- std::string GetFilterType ();
3663-
3664- nux::Property<int> rating;
3665-
3666- protected:
3667- virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
3668- virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
3669- virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
3670-
3671- void OnRatingsRatingChanged(const int& new_rating);
3672- void OnFilterRatingChanged(float new_rating);
3673- void OnAnyButtonActivated(nux::View *view);
3674-
3675- FilterBasicButton *any_button_;
3676- FilterRatingsButton *ratings_;
3677- dash::RatingsFilter::Ptr filter_;
3678-
3679- private:
3680- float last_rating_;
3681- };
3682-
3683-}
3684-
3685-#endif // FILTERRATINGSWIDGET_H
3686+namespace unity
3687+{
3688+namespace dash
3689+{
3690+
3691+class FilterBasicButton;
3692+class FilterRatingsButton;
3693+
3694+class FilterRatingsWidget : public FilterExpanderLabel
3695+{
3696+ NUX_DECLARE_OBJECT_TYPE(FilterRatingsWidget, FilterExpanderLabel);
3697+public:
3698+ FilterRatingsWidget(NUX_FILE_LINE_PROTO);
3699+ virtual ~FilterRatingsWidget();
3700+
3701+ void SetFilter(Filter::Ptr const& filter);
3702+ std::string GetFilterType();
3703+
3704+protected:
3705+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
3706+ virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
3707+
3708+ FilterAllButton* all_button_;
3709+ FilterRatingsButton* ratings_;
3710+ RatingsFilter::Ptr filter_;
3711+};
3712+
3713+} // namespace dash
3714+} // namespace unity
3715+
3716+#endif // UNITYSHELL_FILTERRATINGSWIDGET_H
3717
3718=== added file 'plugins/unityshell/src/FilterWidget.cpp'
3719--- plugins/unityshell/src/FilterWidget.cpp 1970-01-01 00:00:00 +0000
3720+++ plugins/unityshell/src/FilterWidget.cpp 2012-01-11 09:37:33 +0000
3721@@ -0,0 +1,38 @@
3722+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3723+/*
3724+ * Copyright 2011 Canonical Ltd.
3725+ *
3726+ * This program is free software: you can redistribute it and/or modify it
3727+ * under the terms of the GNU Lesser General Public License version 3, as
3728+ * published by the Free Software Foundation.
3729+ *
3730+ * This program is distributed in the hope that it will be useful, but
3731+ * WITHOUT ANY WARRANTY; without even the implied warranties of
3732+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
3733+ * PURPOSE. See the applicable version of the GNU Lesser General Public
3734+ * License for more details.
3735+ *
3736+ * You should have received a copy of both the GNU Lesser General Public
3737+ * License version 3 along with this program. If not, see
3738+ * <http://www.gnu.org/licenses/>
3739+ *
3740+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
3741+ *
3742+ */
3743+
3744+#include "FilterWidget.h"
3745+
3746+namespace unity
3747+{
3748+namespace dash
3749+{
3750+
3751+NUX_IMPLEMENT_OBJECT_TYPE(FilterWidget);
3752+
3753+FilterWidget::FilterWidget( NUX_FILE_LINE_DECL)
3754+ : nux::View(NUX_FILE_LINE_PARAM)
3755+{
3756+}
3757+
3758+} // namespace dash
3759+} // namespace unity
3760
3761=== modified file 'plugins/unityshell/src/FilterWidget.h'
3762--- plugins/unityshell/src/FilterWidget.h 2011-09-12 03:57:01 +0000
3763+++ plugins/unityshell/src/FilterWidget.h 2012-01-11 09:37:33 +0000
3764@@ -19,24 +19,30 @@
3765 * Authored by: Gordon Allott <gord.allott@canonical.com>
3766 *
3767 */
3768-#ifndef UNITY_FILTERWIDGET_H
3769-#define UNITY_FILTERWIDGET_H
3770+#ifndef UNITYSHELL_FILTERWIDGET_H
3771+#define UNITYSHELL_FILTERWIDGET_H
3772
3773+#include <Nux/Nux.h>
3774 #include <Nux/View.h>
3775 #include <UnityCore/Filter.h>
3776
3777-
3778 namespace unity
3779 {
3780+namespace dash
3781+{
3782
3783-class FilterWidget
3784+class FilterWidget : public nux::View
3785 {
3786+ NUX_DECLARE_OBJECT_TYPE(FilterWidget, nux::View);
3787 public:
3788- virtual ~FilterWidget () {}
3789- virtual void SetFilter (dash::Filter::Ptr filter) = 0;
3790- virtual std::string GetFilterType () = 0;
3791+ FilterWidget(NUX_FILE_LINE_PROTO);
3792+ virtual ~FilterWidget() {};
3793+
3794+ virtual void SetFilter(Filter::Ptr const& filter) = 0;
3795+ virtual std::string GetFilterType() = 0;
3796 };
3797
3798-}
3799+} // namespace dash
3800+} // namespace unity
3801
3802-#endif
3803+#endif //UNITYSHELL_FILTERWIDGET_H