~smspillaz/unity/untiy.less-paint-insanity

1529.2.1 by Tim Penhey
Adding some missed nux object type information.
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
1238.4.11 by Gord Allott
restore the actual files
2
/*
3
 * Copyright 2011 Canonical Ltd.
4
 *
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.
8
 *
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.
14
 *
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/>
18
 *
19
 * Authored by: Gordon Allott <gord.allott@canonical.com>
20
 *
21
 */
22
1418.1.1 by Gord Allott
fixed string handling so everything is translatable and using the corrent names for filters
23
#include <glib.h>
24
#include <glib/gi18n-lib.h>
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
25
#include <UnityCore/GLibWrapper.h>
1238.4.11 by Gord Allott
restore the actual files
26
2350.2.1 by Gord Allott
panel and dash moved to subdirectories
27
#include "unity-shared/DashStyle.h"
1238.4.11 by Gord Allott
restore the actual files
28
#include "FilterGenreWidget.h"
29
#include "FilterGenreButton.h"
30
#include "FilterBasicButton.h"
31
1529.2.2 by Tim Penhey
Avoid gratuitous referencing.
32
namespace unity
33
{
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
34
namespace dash
1529.2.2 by Tim Penhey
Avoid gratuitous referencing.
35
{
1238.4.11 by Gord Allott
restore the actual files
36
1529.2.1 by Tim Penhey
Adding some missed nux object type information.
37
NUX_IMPLEMENT_OBJECT_TYPE(FilterGenre);
38
1842.1.1 by Mirco Müller
Fixing the the unity-part of my patch for LP: #841902 for the fourth of fifth time... after it got approved everytime before... seriously WTF
39
FilterGenre::FilterGenre(int columns, NUX_FILE_LINE_DECL)
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
40
 : FilterExpanderLabel(_("Categories"), NUX_FILE_LINE_PARAM)
41
{
2139.1.1 by Andrea Azzarone
Fixes dash layout bugs. Moves padding values in dash::style.
42
  dash::Style& style = dash::Style::Instance();
43
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
44
  InitTheme();
1776.3.16 by Andrea Azzarone
Strips trailing spaces.
45
1776.3.3 by Andrea Azzarone
Fixes "All" button behaviour.
46
  all_button_ = new FilterAllButton(NUX_TRACKER_LOCATION);
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
47
48
  genre_layout_ = new nux::GridHLayout(NUX_TRACKER_LOCATION);
49
  genre_layout_->ForceChildrenSize(true);
50
  genre_layout_->MatchContentSize(true);
2139.1.1 by Andrea Azzarone
Fixes dash layout bugs. Moves padding values in dash::style.
51
  genre_layout_->SetTopAndBottomPadding(style.GetSpaceBetweenFilterWidgets() - style.GetFilterHighlightPadding(), style.GetFilterHighlightPadding());
1776.3.3 by Andrea Azzarone
Fixes "All" button behaviour.
52
  genre_layout_->EnablePartialVisibility(false);
2139.1.1 by Andrea Azzarone
Fixes dash layout bugs. Moves padding values in dash::style.
53
1842.1.1 by Mirco Müller
Fixing the the unity-part of my patch for LP: #841902 for the fourth of fifth time... after it got approved everytime before... seriously WTF
54
  if (columns == 3)
55
  {
2139.1.1 by Andrea Azzarone
Fixes dash layout bugs. Moves padding values in dash::style.
56
    genre_layout_->SetChildrenSize((style.GetFilterBarWidth() - 12 * 2) / 3, style.GetFilterButtonHeight());
57
    genre_layout_->SetSpaceBetweenChildren (12, 12);
1842.1.1 by Mirco Müller
Fixing the the unity-part of my patch for LP: #841902 for the fourth of fifth time... after it got approved everytime before... seriously WTF
58
  }
59
  else
60
  {
2139.1.1 by Andrea Azzarone
Fixes dash layout bugs. Moves padding values in dash::style.
61
    genre_layout_->SetChildrenSize((style.GetFilterBarWidth() - 10 ) / 2, style.GetFilterButtonHeight());
62
    genre_layout_->SetSpaceBetweenChildren (10, 12);
1842.1.1 by Mirco Müller
Fixing the the unity-part of my patch for LP: #841902 for the fourth of fifth time... after it got approved everytime before... seriously WTF
63
  }
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
64
65
  SetRightHandView(all_button_);
66
  SetContents(genre_layout_);
67
}
68
69
FilterGenre::~FilterGenre()
70
{
71
}
72
1776.3.11 by Andrea Azzarone
Fixes.
73
void FilterGenre::SetFilter(Filter::Ptr const& filter)
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
74
{
75
  filter_ = std::static_pointer_cast<CheckOptionFilter>(filter);
1776.3.16 by Andrea Azzarone
Strips trailing spaces.
76
1776.3.3 by Andrea Azzarone
Fixes "All" button behaviour.
77
  all_button_->SetFilter(filter_);
1776.3.17 by Andrea Azzarone
Keep in consideration collapsed property.
78
  expanded = !filter_->collapsed();
2139.1.1 by Andrea Azzarone
Fixes dash layout bugs. Moves padding values in dash::style.
79
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
80
  filter_->option_added.connect(sigc::mem_fun(this, &FilterGenre::OnOptionAdded));
81
  filter_->option_removed.connect(sigc::mem_fun(this, &FilterGenre::OnOptionRemoved));
82
83
  // finally - make sure we are up-todate with our filter list
84
  for (auto it : filter_->options())
85
    OnOptionAdded(it);
86
87
  SetLabel(filter_->name);
88
}
89
1776.3.11 by Andrea Azzarone
Fixes.
90
void FilterGenre::OnOptionAdded(FilterOption::Ptr const& new_filter)
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
91
{
1776.3.11 by Andrea Azzarone
Fixes.
92
  std::string tmp_label(new_filter->name);
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
93
94
  glib::String escape(g_markup_escape_text(tmp_label.c_str(), -1));
95
  std::string label(escape.Value());
96
97
  FilterGenreButton* button = new FilterGenreButton(label, NUX_TRACKER_LOCATION);
98
  button->SetFilter(new_filter);
99
  genre_layout_->AddView(button, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
100
  buttons_.push_back(button);
101
}
102
1776.3.11 by Andrea Azzarone
Fixes.
103
void FilterGenre::OnOptionRemoved(FilterOption::Ptr const& removed_filter)
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
104
{
1776.3.11 by Andrea Azzarone
Fixes.
105
  for (auto it=buttons_.begin() ; it != buttons_.end(); ++it)
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
106
  {
107
    if ((*it)->GetFilter() == removed_filter)
1238.4.13 by Gord Allott
save point
108
    {
109
      genre_layout_->RemoveChildObject(*it);
1455.3.9 by Tim Penhey
Unreference the buttons when removed from the layout.
110
      buttons_.erase(it);
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
111
      break;
1238.4.13 by Gord Allott
save point
112
    }
1238.4.11 by Gord Allott
restore the actual files
113
  }
1776.3.2 by Andrea Azzarone
Updates dash filters coding style.
114
}
115
116
std::string FilterGenre::GetFilterType()
117
{
118
  return "FilterBasicButton";
119
}
120
121
void FilterGenre::InitTheme()
122
{
123
  //FIXME - build theme here - store images, cache them, fun fun fun
124
}
125
126
} // namespace dash
127
} // namespace unity