~azzar1/unity/shortcut-hint

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/FilterExpanderLabel.cpp

  • Committer: Andrea Azzarone
  • Date: 2012-01-13 15:35:44 UTC
  • mfrom: (1739.1.92 unity)
  • Revision ID: azzaronea@gmail.com-20120113153544-g01rcc44wrbkjsg8
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 *
21
21
 */
22
22
 
23
 
#include "config.h"
24
 
 
25
 
#include <Nux/Nux.h>
26
 
 
 
23
#include "DashStyle.h"
27
24
#include "FilterBasicButton.h"
28
25
#include "FilterExpanderLabel.h"
29
 
#include "DashStyle.h"
30
26
 
31
 
namespace unity {
 
27
namespace unity
 
28
{
 
29
namespace dash
 
30
{
32
31
 
33
32
NUX_IMPLEMENT_OBJECT_TYPE(FilterExpanderLabel);
34
33
 
35
 
  FilterExpanderLabel::FilterExpanderLabel (std::string label, NUX_FILE_LINE_DECL)
36
 
      : nux::View (NUX_FILE_LINE_PARAM)
37
 
      , expanded (true)
38
 
      , top_bar_layout_ (NULL)
39
 
      , contents_ (NULL)
40
 
      , right_hand_contents_ (NULL)
41
 
      , expander_graphic_ (NULL)
42
 
      , label_("<span size='larger' weight='bold'>" + label + "</span>")
43
 
  {
44
 
    expanded.changed.connect (sigc::mem_fun(this, &FilterExpanderLabel::DoExpandChange));
45
 
    BuildLayout ();
46
 
  }
47
 
 
48
 
  FilterExpanderLabel::~FilterExpanderLabel() {
49
 
 
50
 
  }
51
 
 
52
 
  void FilterExpanderLabel::SetLabel (std::string label)
53
 
  {
54
 
    label_ = "<span size='larger' weight='bold'>" + label + "</span>";
55
 
    cairo_label_->SetText(label_.c_str());
56
 
  }
57
 
 
58
 
  void FilterExpanderLabel::SetRightHandView (nux::View *view)
59
 
  {
60
 
    view->SetMaximumHeight(30);
61
 
 
62
 
    right_hand_contents_ = view;
63
 
    top_bar_layout_->AddView(right_hand_contents_, 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
64
 
  }
65
 
 
66
 
  void FilterExpanderLabel::SetContents (nux::Layout *contents)
67
 
  {
68
 
    contents_ = contents;
69
 
    contents_->SetVisible(expanded);
70
 
    layout_->AddLayout (contents_, 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
71
 
 
72
 
    QueueDraw();
73
 
  }
74
 
 
75
 
  void FilterExpanderLabel::BuildLayout ()
76
 
  {
77
 
    layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
78
 
    top_bar_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
79
 
 
80
 
    cairo_label_ = new nux::StaticText(label_.c_str(), NUX_TRACKER_LOCATION);
81
 
    cairo_label_->SetFontName("Ubuntu 10");
82
 
    cairo_label_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
83
 
    cairo_label_->mouse_down.connect(
84
 
      [&](int x, int y, unsigned long button_flags, unsigned long key_flag)
85
 
      {
86
 
        expanded = !expanded;
87
 
        if (contents_)
88
 
          contents_->SetVisible(expanded);
89
 
        QueueDraw();
90
 
      });
91
 
 
92
 
    top_bar_layout_->AddView (cairo_label_, 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
93
 
    top_bar_layout_->AddSpace(1, 1);
94
 
 
95
 
    top_bar_layout_->SetMaximumWidth((dash::Style::Instance().GetTileWidth() -12)*2+10);
96
 
 
97
 
    layout_->AddLayout (top_bar_layout_, 0, nux::MINOR_POSITION_LEFT);
98
 
    layout_->SetVerticalInternalMargin(0);
99
 
 
100
 
    SetLayout(layout_);
101
 
 
102
 
    QueueRelayout();
103
 
    NeedRedraw();
104
 
  }
105
 
 
106
 
  void FilterExpanderLabel::DoExpandChange (bool change)
107
 
  {
108
 
    if (contents_)
109
 
      contents_->SetVisible(change);
110
 
 
111
 
    QueueRelayout();
112
 
  }
113
 
 
114
 
  void FilterExpanderLabel::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {
115
 
    nux::Geometry geo = GetGeometry();
116
 
 
117
 
    GfxContext.PushClippingRectangle(geo);
118
 
    nux::GetPainter().PaintBackground(GfxContext, geo);
119
 
    GfxContext.PopClippingRectangle();
120
 
  }
121
 
 
122
 
  void FilterExpanderLabel::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
123
 
    GfxContext.PushClippingRectangle(GetGeometry());
124
 
 
125
 
    GetLayout()->ProcessDraw(GfxContext, force_draw);
126
 
 
127
 
    GfxContext.PopClippingRectangle();
128
 
  }
129
 
 
130
 
  void FilterExpanderLabel::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
131
 
    nux::View::PostDraw(GfxContext, force_draw);
132
 
  }
133
 
 
134
 
};
 
34
FilterExpanderLabel::FilterExpanderLabel(std::string const& label, NUX_FILE_LINE_DECL)
 
35
  : FilterWidget(NUX_FILE_LINE_PARAM)
 
36
  , expanded(true)
 
37
  , layout_(nullptr)
 
38
  , top_bar_layout_(nullptr)
 
39
  , right_hand_contents_(nullptr)
 
40
  , expander_graphic_(nullptr)
 
41
  , cairo_label_(nullptr)
 
42
  , raw_label_(label)
 
43
  , label_("<span size='larger' weight='bold'>" + label + "</span>" + "  ▾")
 
44
{
 
45
  expanded.changed.connect(sigc::mem_fun(this, &FilterExpanderLabel::DoExpandChange));
 
46
  BuildLayout();
 
47
}
 
48
 
 
49
FilterExpanderLabel::~FilterExpanderLabel()
 
50
{
 
51
}
 
52
 
 
53
void FilterExpanderLabel::SetLabel(std::string const& label)
 
54
{
 
55
  raw_label_ = label;
 
56
 
 
57
  label_ = "<span size='larger' weight='bold'>";
 
58
  label_ += raw_label_;
 
59
  label_ += "</span>";
 
60
  label_ += expanded ? "  ▾" : "  ▸";
 
61
  cairo_label_->SetText(label_.c_str());
 
62
}
 
63
 
 
64
void FilterExpanderLabel::SetRightHandView(nux::View* view)
 
65
{
 
66
  view->SetMaximumHeight(30);
 
67
 
 
68
  right_hand_contents_ = view;
 
69
  top_bar_layout_->AddView(right_hand_contents_, 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
 
70
}
 
71
 
 
72
void FilterExpanderLabel::SetContents(nux::Layout* contents)
 
73
{
 
74
  contents_.Adopt(contents);
 
75
 
 
76
  layout_->AddLayout(contents_.GetPointer(), 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
 
77
  top_bar_layout_->SetTopAndBottomPadding(0);
 
78
 
 
79
  QueueDraw();
 
80
}
 
81
 
 
82
void FilterExpanderLabel::BuildLayout()
 
83
{
 
84
  layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
 
85
  top_bar_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
 
86
 
 
87
  cairo_label_ = new nux::StaticText(label_.c_str(), NUX_TRACKER_LOCATION);
 
88
  cairo_label_->SetFontName("Ubuntu 10");
 
89
  cairo_label_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
 
90
  cairo_label_->mouse_down.connect(
 
91
    [&](int x, int y, unsigned long button_flags, unsigned long key_flag)
 
92
    {
 
93
      expanded = !expanded;
 
94
    });
 
95
 
 
96
  top_bar_layout_->AddView(cairo_label_, 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
 
97
  top_bar_layout_->AddSpace(1, 1);
 
98
 
 
99
  top_bar_layout_->SetMaximumWidth((Style::Instance().GetTileWidth() - 12) * 2 + 10);
 
100
 
 
101
  layout_->AddLayout(top_bar_layout_, 0, nux::MINOR_POSITION_LEFT);
 
102
  layout_->SetVerticalInternalMargin(0);
 
103
 
 
104
  SetLayout(layout_);
 
105
 
 
106
  QueueRelayout();
 
107
  NeedRedraw();
 
108
}
 
109
 
 
110
void FilterExpanderLabel::DoExpandChange(bool change)
 
111
{
 
112
  label_ = "<span size='larger' weight='bold'>";
 
113
  label_ += raw_label_;
 
114
  label_ += "</span>";
 
115
  label_ += expanded ? "  ▾" : "  ▸";
 
116
 
 
117
  if (cairo_label_)
 
118
    cairo_label_->SetText(label_);
 
119
 
 
120
  if (change and contents_ and !contents_->IsChildOf(layout_))
 
121
  {
 
122
    layout_->AddLayout(contents_.GetPointer(), 1, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
 
123
    top_bar_layout_->SetTopAndBottomPadding(0);
 
124
  }
 
125
  else if (!change and contents_ and contents_->IsChildOf(layout_))
 
126
  {
 
127
    layout_->RemoveChildObject(contents_.GetPointer());
 
128
    top_bar_layout_->SetTopAndBottomPadding(0, 10);
 
129
  }
 
130
 
 
131
  layout_->ComputeContentSize();
 
132
  QueueDraw();
 
133
}
 
134
 
 
135
void FilterExpanderLabel::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
 
136
{
 
137
  nux::Geometry const& geo = GetGeometry();
 
138
 
 
139
  GfxContext.PushClippingRectangle(geo);
 
140
  nux::GetPainter().PaintBackground(GfxContext, geo);
 
141
  GfxContext.PopClippingRectangle();
 
142
}
 
143
 
 
144
void FilterExpanderLabel::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
 
145
{
 
146
  GfxContext.PushClippingRectangle(GetGeometry());
 
147
  GetLayout()->ProcessDraw(GfxContext, force_draw);
 
148
  GfxContext.PopClippingRectangle();
 
149
}
 
150
 
 
151
} // namespace dash
 
152
} // namespace unity