Back to index

unity  6.0.0
FilterRatingsWidget.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2011 Canonical Ltd.
00004  *
00005  * This program is free software: you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License version 3, as
00007  * published by the  Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License version 3 along with this program.  If not, see
00017  * <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Gordon Allott <gord.allott@canonical.com>
00020  *
00021  */
00022 
00023 #include <Nux/Nux.h>
00024 #include <glib.h>
00025 #include <glib/gi18n-lib.h>
00026 
00027 #include "unity-shared/DashStyle.h"
00028 #include "FilterGenreWidget.h"
00029 #include "FilterGenreButton.h"
00030 #include "FilterBasicButton.h"
00031 #include "FilterRatingsButton.h"
00032 #include "FilterRatingsWidget.h"
00033 
00034 namespace
00035 {
00036 const int star_size      = 28;
00037 }
00038 
00039 namespace unity
00040 {
00041 namespace dash
00042 {
00043 
00044 NUX_IMPLEMENT_OBJECT_TYPE(FilterRatingsWidget);
00045 
00046 FilterRatingsWidget::FilterRatingsWidget(NUX_FILE_LINE_DECL)
00047   : FilterExpanderLabel(_("Rating"), NUX_FILE_LINE_PARAM)
00048 {
00049   all_button_ = new FilterAllButton(NUX_TRACKER_LOCATION);
00050 
00051   dash::Style& style = dash::Style::Instance();
00052   const int top_padding    = style.GetSpaceBetweenFilterWidgets() - style.GetFilterHighlightPadding() - 1; // -1 (PNGs have an 1px top padding)
00053   const int bottom_padding = style.GetFilterHighlightPadding();
00054 
00055   nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION);
00056   layout->SetTopAndBottomPadding(top_padding, bottom_padding);
00057   ratings_ = new FilterRatingsButton(NUX_TRACKER_LOCATION);
00058   ratings_->SetMinimumHeight(star_size);
00059 
00060   layout->AddView(ratings_);
00061 
00062   SetRightHandView(all_button_);
00063   SetContents(layout);
00064 }
00065 
00066 FilterRatingsWidget::~FilterRatingsWidget()
00067 {
00068 }
00069 
00070 void FilterRatingsWidget::SetFilter(Filter::Ptr const& filter)
00071 {
00072   filter_ = std::static_pointer_cast<RatingsFilter>(filter);
00073 
00074   all_button_->SetFilter(filter_);
00075   expanded = !filter_->collapsed();
00076   ratings_->SetFilter(filter_);
00077 
00078   SetLabel(filter_->name);
00079   NeedRedraw();
00080 }
00081 
00082 std::string FilterRatingsWidget::GetFilterType()
00083 {
00084   return "FilterRatingsWidget";
00085 }
00086 
00087 } // namespace dash
00088 } // namespace unity