Merge lp:~3v1n0/unity/panel-p-indicators-view into lp:~3v1n0/unity/panel-p-indicator-entry

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merge reported by: Marco Trevisan (Treviño)
Merged at revision: not available
Proposed branch: lp:~3v1n0/unity/panel-p-indicators-view
Merge into: lp:~3v1n0/unity/panel-p-indicator-entry
Diff against target: 401 lines (+130/-60)
2 files modified
plugins/unityshell/src/PanelIndicatorsView.cpp (+103/-42)
plugins/unityshell/src/PanelIndicatorsView.h (+27/-18)
To merge this branch: bzr merge lp:~3v1n0/unity/panel-p-indicators-view
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Marco Trevisan (Treviño) Pending
Review via email: mp+100121@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Again, don't use "using namespace indicator;" in a header file.

review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Fixed.

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

Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/PanelIndicatorsView.cpp'
2--- plugins/unityshell/src/PanelIndicatorsView.cpp 2012-03-21 12:31:11 +0000
3+++ plugins/unityshell/src/PanelIndicatorsView.cpp 2012-04-02 10:28:19 +0000
4@@ -1,6 +1,6 @@
5 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
6 /*
7- * Copyright (C) 2011 Canonical Ltd
8+ * Copyright (C) 2011-2012 Canonical Ltd
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 3 as
12@@ -14,7 +14,7 @@
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16- * Authored by: Marco Trevisan (Treviño) <mail@3v1n0.net>
17+ * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
18 * Neil Jagdish Patel <neil.patel@canonical.com>
19 */
20
21@@ -36,6 +36,8 @@
22
23 namespace unity
24 {
25+using namespace indicator;
26+
27 NUX_IMPLEMENT_OBJECT_TYPE(PanelIndicatorsView);
28
29 PanelIndicatorsView::PanelIndicatorsView()
30@@ -45,8 +47,9 @@
31 {
32 LOG_DEBUG(logger) << "Indicators View Added: ";
33 layout_ = new nux::HLayout("", NUX_TRACKER_LOCATION);
34+ layout_->SetContentDistribution(nux::eStackRight);
35
36- SetCompositionLayout(layout_);
37+ SetLayout(layout_);
38 }
39
40 PanelIndicatorsView::~PanelIndicatorsView()
41@@ -59,7 +62,7 @@
42 }
43
44 void
45-PanelIndicatorsView::AddIndicator(indicator::Indicator::Ptr const& indicator)
46+PanelIndicatorsView::AddIndicator(Indicator::Ptr const& indicator)
47 {
48 LOG_DEBUG(logger) << "IndicatorAdded: " << indicator->name();
49 indicators_.push_back(indicator);
50@@ -76,7 +79,7 @@
51 }
52
53 void
54-PanelIndicatorsView::RemoveIndicator(indicator::Indicator::Ptr const& indicator)
55+PanelIndicatorsView::RemoveIndicator(Indicator::Ptr const& indicator)
56 {
57 auto connections = indicators_connections_.find(indicator);
58
59@@ -88,7 +91,7 @@
60 }
61
62 for (auto entry : indicator->GetEntries())
63- OnEntryRemoved (entry->id());
64+ OnEntryRemoved(entry->id());
65
66 for (auto i = indicators_.begin(); i != indicators_.end(); i++)
67 {
68@@ -102,6 +105,12 @@
69 LOG_DEBUG(logger) << "IndicatorRemoved: " << indicator->name();
70 }
71
72+PanelIndicatorsView::Indicators
73+PanelIndicatorsView::GetIndicators()
74+{
75+ return indicators_;
76+}
77+
78 void
79 PanelIndicatorsView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
80 {
81@@ -121,16 +130,45 @@
82 entry.second->QueueDraw();
83 }
84
85+void
86+PanelIndicatorsView::SetMaximumEntriesWidth(int max_width)
87+{
88+ unsigned int n_entries = 0;
89+
90+ for (auto entry : entries_)
91+ if (entry.second->IsVisible())
92+ n_entries++;
93+
94+ if (n_entries > 0)
95+ {
96+ for (auto entry : entries_)
97+ {
98+ if (entry.second->IsVisible() && n_entries > 0)
99+ {
100+ int max_entry_width = max_width / n_entries;
101+
102+ if (entry.second->GetBaseWidth() > max_entry_width)
103+ entry.second->SetMaximumWidth(max_entry_width);
104+
105+ max_width -= entry.second->GetBaseWidth();
106+ --n_entries;
107+ }
108+ }
109+ }
110+}
111+
112 PanelIndicatorEntryView*
113-PanelIndicatorsView::ActivateEntry(std::string const& entry_id)
114+PanelIndicatorsView::ActivateEntry(std::string const& entry_id, int button)
115 {
116 auto entry = entries_.find(entry_id);
117
118- if (entry != entries_.end() && entry->second->IsEntryValid())
119+ if (entry != entries_.end())
120 {
121 PanelIndicatorEntryView* view = entry->second;
122- LOG_DEBUG(logger) << "Activating: " << entry_id;
123- view->Activate();
124+
125+ if (view->IsSensitive() && view->IsVisible())
126+ view->Activate(button);
127+
128 return view;
129 }
130
131@@ -148,24 +186,27 @@
132 for (auto entry : sorted_entries)
133 {
134 PanelIndicatorEntryView* view = entry.second;
135- if (view->IsSensitive())
136+
137+ if (view->IsSensitive() && view->IsVisible() && view->IsFocused())
138 {
139- view->Activate();
140+ /* Use the 0 button, it means it's a keyboard activation */
141+ view->Activate(0);
142 return true;
143 }
144 }
145+
146 return false;
147 }
148
149 void
150-PanelIndicatorsView::GetGeometryForSync(indicator::EntryLocationMap& locations)
151+PanelIndicatorsView::GetGeometryForSync(EntryLocationMap& locations)
152 {
153 for (auto entry : entries_)
154 entry.second->GetGeometryForSync(locations);
155 }
156
157 PanelIndicatorEntryView*
158-PanelIndicatorsView::ActivateEntryAt(int x, int y)
159+PanelIndicatorsView::ActivateEntryAt(int x, int y, int button)
160 {
161 PanelIndicatorEntryView* target = nullptr;
162 bool found_old_active = false;
163@@ -180,9 +221,10 @@
164 {
165 PanelIndicatorEntryView* view = entry.second;
166
167- if (!target && view->IsVisible() && view->GetAbsoluteGeometry().IsPointInside(x, y))
168+ if (!target && view->IsVisible() && view->IsFocused() &&
169+ view->GetAbsoluteGeometry().IsPointInside(x, y))
170 {
171- view->Activate(0);
172+ view->Activate(button);
173 target = view;
174 break;
175 }
176@@ -219,11 +261,13 @@
177 GfxContext.PopClippingRectangle();
178 }
179
180-PanelIndicatorEntryView *
181-PanelIndicatorsView::AddEntry(indicator::Entry::Ptr const& entry, int padding,
182- IndicatorEntryPosition pos, IndicatorEntryType type)
183+void
184+PanelIndicatorsView::AddEntryView(PanelIndicatorEntryView* view,
185+ IndicatorEntryPosition pos)
186 {
187- auto view = new PanelIndicatorEntryView(entry, padding, type);
188+ if (!view)
189+ return;
190+
191 int entry_pos = pos;
192
193 view->SetOpacity(opacity_);
194@@ -233,7 +277,7 @@
195 {
196 entry_pos = nux::NUX_LAYOUT_BEGIN;
197
198- if (entry->priority() > -1)
199+ if (view->GetEntryPriority() > -1)
200 {
201 for (auto area : layout_->GetChildren())
202 {
203@@ -241,7 +285,7 @@
204
205 if (en)
206 {
207- if (en && entry->priority() <= en->GetEntryPriority())
208+ if (en && view->GetEntryPriority() <= en->GetEntryPriority())
209 break;
210
211 entry_pos++;
212@@ -251,20 +295,28 @@
213 }
214
215 layout_->AddView(view, 0, nux::eCenter, nux::eFull, 1.0, (nux::LayoutPosition) entry_pos);
216- layout_->SetContentDistribution(nux::eStackRight);
217- entries_[entry->id()] = view;
218+
219+ entries_[view->GetEntryID()] = view;
220
221 AddChild(view);
222 QueueRelayout();
223 QueueDraw();
224
225 on_indicator_updated.emit(view);
226+}
227+
228+PanelIndicatorEntryView *
229+PanelIndicatorsView::AddEntry(Entry::Ptr const& entry, int padding,
230+ IndicatorEntryPosition pos, IndicatorEntryType type)
231+{
232+ auto view = new PanelIndicatorEntryView(entry, padding, type);
233+ AddEntryView(view, pos);
234
235 return view;
236 }
237
238 void
239-PanelIndicatorsView::OnEntryAdded(indicator::Entry::Ptr const& entry)
240+PanelIndicatorsView::OnEntryAdded(Entry::Ptr const& entry)
241 {
242 AddEntry(entry);
243 }
244@@ -279,19 +331,25 @@
245 }
246
247 void
248+PanelIndicatorsView::RemoveEntryView(PanelIndicatorEntryView* view)
249+{
250+ if (!view)
251+ return;
252+
253+ std::string const& entry_id = view->GetEntryID();
254+ RemoveChild(view);
255+ on_indicator_updated.emit(view);
256+ entries_.erase(entry_id);
257+ layout_->RemoveChildObject(view);
258+
259+ QueueRelayout();
260+ QueueDraw();
261+}
262+
263+void
264 PanelIndicatorsView::RemoveEntry(std::string const& entry_id)
265 {
266- PanelIndicatorEntryView* view = entries_[entry_id];
267-
268- if (view)
269- {
270- layout_->RemoveChildObject(view);
271- entries_.erase(entry_id);
272- on_indicator_updated.emit(view);
273-
274- QueueRelayout();
275- QueueDraw();
276- }
277+ RemoveEntryView(entries_[entry_id]);
278 }
279
280 void
281@@ -301,17 +359,17 @@
282 }
283
284 void
285-PanelIndicatorsView::DashShown()
286+PanelIndicatorsView::OverlayShown()
287 {
288 for (auto entry: entries_)
289- entry.second->DashShown();
290+ entry.second->OverlayShown();
291 }
292
293 void
294-PanelIndicatorsView::DashHidden()
295+PanelIndicatorsView::OverlayHidden()
296 {
297 for (auto entry: entries_)
298- entry.second->DashHidden();
299+ entry.second->OverlayHidden();
300 }
301
302 double
303@@ -337,13 +395,16 @@
304
305 std::string PanelIndicatorsView::GetName() const
306 {
307- return "IndicatorsView";
308+ return "Indicators";
309 }
310
311 void
312 PanelIndicatorsView::AddProperties(GVariantBuilder* builder)
313 {
314- variant::BuilderWrapper(builder).add(GetGeometry());
315+ variant::BuilderWrapper(builder)
316+ .add(GetGeometry())
317+ .add("entries", entries_.size())
318+ .add("opacity", opacity_);
319 }
320
321 } // namespace unity
322
323=== modified file 'plugins/unityshell/src/PanelIndicatorsView.h'
324--- plugins/unityshell/src/PanelIndicatorsView.h 2012-03-21 12:31:11 +0000
325+++ plugins/unityshell/src/PanelIndicatorsView.h 2012-04-02 10:28:19 +0000
326@@ -42,11 +42,11 @@
327 void AddIndicator(indicator::Indicator::Ptr const& indicator);
328 void RemoveIndicator(indicator::Indicator::Ptr const& indicator);
329
330- typedef enum {
331+ enum IndicatorEntryPosition {
332 AUTO = -1,
333 START = nux::NUX_LAYOUT_BEGIN,
334 END = nux::NUX_LAYOUT_END,
335- } IndicatorEntryPosition;
336+ };
337
338 typedef PanelIndicatorEntryView::IndicatorEntryType IndicatorEntryType;
339
340@@ -56,37 +56,46 @@
341 IndicatorEntryType type = IndicatorEntryType::INDICATOR);
342 void RemoveEntry(std::string const& entry_id);
343
344- PanelIndicatorEntryView* ActivateEntryAt(int x, int y);
345- PanelIndicatorEntryView* ActivateEntry(std::string const& entry_id);
346+ PanelIndicatorEntryView* ActivateEntryAt(int x, int y, int button = 1);
347+ PanelIndicatorEntryView* ActivateEntry(std::string const& entry_id, int button = 1);
348 bool ActivateIfSensitive();
349+
350+ virtual void OverlayShown();
351+ virtual void OverlayHidden();
352+
353+ void SetOpacity(double opacity);
354+ double GetOpacity();
355+
356+ void SetMaximumEntriesWidth(int max_width);
357 void GetGeometryForSync(indicator::EntryLocationMap& locations);
358
359+ virtual void QueueDraw();
360+
361+ sigc::signal<void, PanelIndicatorEntryView*> on_indicator_updated;
362+
363+protected:
364+ std::string GetName() const;
365+ void AddProperties(GVariantBuilder* builder);
366+
367+ typedef std::vector<indicator::Indicator::Ptr> Indicators;
368+ Indicators GetIndicators();
369+
370 virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
371 virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
372- virtual void QueueDraw();
373
374 virtual void OnEntryAdded(indicator::Entry::Ptr const& entry);
375 virtual void OnEntryRefreshed(PanelIndicatorEntryView* view);
376 virtual void OnEntryRemoved(std::string const& entry_id);
377
378- void DashShown();
379- void DashHidden();
380-
381- void SetOpacity(double opacity);
382- double GetOpacity();
383-
384- sigc::signal<void, PanelIndicatorEntryView*> on_indicator_updated;
385-
386-protected:
387+ virtual void AddEntryView(PanelIndicatorEntryView* view,
388+ IndicatorEntryPosition pos = AUTO);
389+ virtual void RemoveEntryView(PanelIndicatorEntryView* view);
390+
391 nux::HLayout* layout_;
392 typedef std::map<std::string, PanelIndicatorEntryView*> Entries;
393 Entries entries_;
394
395- std::string GetName() const;
396- void AddProperties(GVariantBuilder* builder);
397-
398 private:
399- typedef std::vector<indicator::Indicator::Ptr> Indicators;
400 Indicators indicators_;
401 double opacity_;
402

Subscribers

People subscribed via source and target branches

to all changes: