1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright 2011 Canonical Ltd.
5
* This program is free software: you can redistribute it and/or modify it
6
* under the terms of the GNU Lesser General Public License version 3, as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranties of
11
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12
* PURPOSE. See the applicable version of the GNU Lesser General Public
13
* License for more details.
15
* You should have received a copy of both the GNU Lesser General Public
16
* License version 3 along with this program. If not, see
17
* <http://www.gnu.org/licenses/>
19
* Authored by: Gordon Allott <gord.allott@canonical.com>
27
#include "FilterMultiRangeWidget.h"
28
#include "FilterMultiRangeButton.h"
29
#include "FilterBasicButton.h"
32
#include <glib/gi18n-lib.h>
36
NUX_IMPLEMENT_OBJECT_TYPE(FilterMultiRange);
38
FilterMultiRange::FilterMultiRange (NUX_FILE_LINE_DECL)
39
: FilterExpanderLabel (_("Multi-range"), NUX_FILE_LINE_PARAM)
40
, all_selected (false) {
43
all_button_ = new FilterBasicButton(_("All"), NUX_TRACKER_LOCATION);
44
all_button_->activated.connect(sigc::mem_fun(this, &FilterMultiRange::OnAllActivated));
45
all_button_->label = _("All");
47
layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
48
layout_->SetVerticalExternalMargin (12);
50
SetRightHandView(all_button_);
52
OnActiveChanged(false);
55
FilterMultiRange::~FilterMultiRange()
59
void FilterMultiRange::SetFilter(dash::Filter::Ptr filter)
61
filter_ = std::static_pointer_cast<dash::MultiRangeFilter>(filter);
63
filter_->option_added.connect (sigc::mem_fun (this, &FilterMultiRange::OnOptionAdded));
64
filter_->option_removed.connect(sigc::mem_fun (this, &FilterMultiRange::OnOptionRemoved));
66
// finally - make sure we are up-todate with our filter list
67
dash::MultiRangeFilter::Options::iterator it;
68
dash::MultiRangeFilter::Options options = filter_->options;
69
for (it = options.begin(); it < options.end(); it++)
72
SetLabel(filter_->name);
75
void FilterMultiRange::OnActiveChanged(bool value)
77
// go through all the buttons, and set the state :(
79
std::vector<FilterMultiRangeButton*>::iterator it;
83
for ( it=buttons_.begin() ; it < buttons_.end(); it++ )
85
FilterMultiRangeButton* button = (*it);
86
dash::FilterOption::Ptr filter = button->GetFilter();
87
bool tmp_active = filter->active;
88
button->active = tmp_active;
103
for ( it=buttons_.begin() ; it < buttons_.end(); it++ )
105
FilterMultiRangeButton* button = (*it);
107
if (index == start && index == end)
108
button->SetHasArrow(MultiRangeArrow::MULTI_RANGE_ARROW_BOTH);
109
else if (index == start)
110
button->SetHasArrow(MultiRangeArrow::MULTI_RANGE_ARROW_LEFT);
111
else if (index == end)
112
button->SetHasArrow(MultiRangeArrow::MULTI_RANGE_ARROW_RIGHT);
114
button->SetHasArrow(MultiRangeArrow::MULTI_RANGE_ARROW_NONE);
117
button->SetVisualSide(MULTI_RANGE_SIDE_LEFT);
118
else if (index == (int)buttons_.size() - 1)
119
button->SetVisualSide(MULTI_RANGE_SIDE_RIGHT);
121
button->SetVisualSide(MULTI_RANGE_CENTER);
127
void FilterMultiRange::OnOptionAdded(dash::FilterOption::Ptr new_filter)
129
FilterMultiRangeButton* button = new FilterMultiRangeButton (NUX_TRACKER_LOCATION);
130
button->SetFilter (new_filter);
131
layout_->AddView (button, 1);
132
buttons_.push_back (button);
133
new_filter->active.changed.connect(sigc::mem_fun (this, &FilterMultiRange::OnActiveChanged));
134
OnActiveChanged(false);
138
void FilterMultiRange::OnOptionRemoved(dash::FilterOption::Ptr removed_filter)
140
std::vector<FilterMultiRangeButton*>::iterator it;
141
FilterMultiRangeButton* found_filter = NULL;
142
for ( it=buttons_.begin() ; it < buttons_.end(); it++ )
144
if ((*it)->GetFilter() == removed_filter)
153
layout_->RemoveChildObject(*it);
157
OnActiveChanged(false);
160
std::string FilterMultiRange::GetFilterType ()
162
return "FilterMultiRange";
165
void FilterMultiRange::InitTheme()
167
//FIXME - build theme here - store images, cache them, fun fun fun
170
void FilterMultiRange::OnAllActivated(nux::View *view)
176
long int FilterMultiRange::ProcessEvent(nux::IEvent& ievent, long int TraverseInfo, long int ProcessEventInfo) {
177
return GetLayout()->ProcessEvent(ievent, TraverseInfo, ProcessEventInfo);
180
void FilterMultiRange::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
181
nux::Geometry geo = GetGeometry();
182
nux::Color col(0.2f, 0.2f, 0.2f, 0.2f);
184
GfxContext.PushClippingRectangle(geo);
185
nux::GetPainter().PaintBackground(GfxContext, geo);
187
nux::GetPainter().Draw2DLine(GfxContext,
188
geo.x, geo.y + geo.height - 1,
189
geo.x + geo.width, geo.y + geo.height - 1,
193
GfxContext.PopClippingRectangle();
196
void FilterMultiRange::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
197
GfxContext.PushClippingRectangle(GetGeometry());
199
GetLayout()->ProcessDraw(GfxContext, force_draw);
201
GfxContext.PopClippingRectangle();
204
void FilterMultiRange::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
205
nux::View::PostDraw(GfxContext, force_draw);