summaryrefslogtreecommitdiff
path: root/panel
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2014-01-30 15:26:45 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2014-01-30 15:26:45 +0100
commitfda91dc6eb5ee11e676ceeaf50049881f4f47b42 (patch)
treefa44e439ec9ea0d631fb2603d5bdaef3efc7e297 /panel
parentd2b9db491631a683f78bc9ee869f5cfe9fbffaf5 (diff)
PanelIndicatorsView: add EnableDropdownMenu, if enabled we add a PanelIndicatorEntryDropdownView
That dropdown is used to adjust the size of the children, hiding them under a dropdown icon instead of collapsing or loosing their control. This is motly unseful only for PanelMenuView, but it might be enabled also for standard indicators. Including, as often, some code cleanup, removing useless dynamic_casts and iterate over layout_->Children()'s instead that over entries. Added entry_added and entry_removed signals. (bzr r3566.5.295)
Diffstat (limited to 'panel')
-rw-r--r--panel/PanelIndicatorsView.cpp138
-rw-r--r--panel/PanelIndicatorsView.h15
2 files changed, 97 insertions, 56 deletions
diff --git a/panel/PanelIndicatorsView.cpp b/panel/PanelIndicatorsView.cpp
index 33a14dbca..d141f5dea 100644
--- a/panel/PanelIndicatorsView.cpp
+++ b/panel/PanelIndicatorsView.cpp
@@ -25,6 +25,7 @@
#include <NuxCore/Logger.h>
#include "PanelIndicatorsView.h"
+#include "PanelIndicatorEntryDropdownView.h"
DECLARE_LOGGER(logger, "unity.indicators");
@@ -48,6 +49,20 @@ PanelIndicatorsView::PanelIndicatorsView()
LOG_DEBUG(logger) << "Indicators View Added: ";
}
+void PanelIndicatorsView::EnableDropdownMenu(bool enable, indicator::Indicators::Ptr const& indicators)
+{
+ if (enable && indicators)
+ {
+ dropdown_ = new PanelIndicatorEntryDropdownView(GetName(), indicators);
+ AddEntryView(dropdown_.GetPointer());
+ }
+ else
+ {
+ RemoveEntryView(dropdown_.GetPointer());
+ dropdown_.Release();
+ }
+}
+
void PanelIndicatorsView::AddIndicator(Indicator::Ptr const& indicator)
{
LOG_DEBUG(logger) << "IndicatorAdded: " << indicator->name();
@@ -58,7 +73,7 @@ void PanelIndicatorsView::AddIndicator(Indicator::Ptr const& indicator)
auto& conn_manager = indicators_connections_[indicator];
conn_manager.Add(indicator->on_entry_added.connect(sigc::mem_fun(this, &PanelIndicatorsView::OnEntryAdded)));
- conn_manager.Add(indicator->on_entry_removed.connect(sigc::mem_fun(this, &PanelIndicatorsView::OnEntryRemoved)));
+ conn_manager.Add(indicator->on_entry_removed.connect(sigc::mem_fun(this, &PanelIndicatorsView::RemoveEntry)));
}
void PanelIndicatorsView::RemoveIndicator(Indicator::Ptr const& indicator)
@@ -66,9 +81,9 @@ void PanelIndicatorsView::RemoveIndicator(Indicator::Ptr const& indicator)
indicators_connections_.erase(indicator);
for (auto const& entry : indicator->GetEntries())
- OnEntryRemoved(entry->id());
+ RemoveEntry(entry->id());
- for (auto i = indicators_.begin(); i != indicators_.end(); i++)
+ for (auto i = indicators_.begin(); i != indicators_.end(); ++i)
{
if (*i == indicator)
{
@@ -96,26 +111,47 @@ void PanelIndicatorsView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
void PanelIndicatorsView::SetMaximumEntriesWidth(int max_width)
{
- unsigned int n_entries = 0;
+ if (!dropdown_)
+ return;
- for (auto const& entry : entries_)
- if (entry.second->IsVisible())
- n_entries++;
+ int accumolated_width = dropdown_->GetBaseWidth();
+ std::vector<PanelIndicatorEntryView::Ptr> to_hide;
- if (n_entries > 0)
+ for (auto* area : layout_->GetChildren())
{
- for (auto const& entry : entries_)
- {
- if (entry.second->IsVisible() && n_entries > 0)
- {
- int max_entry_width = max_width / n_entries;
+ auto en = static_cast<PanelIndicatorEntryView*>(area);
+ if (en == dropdown_.GetPointer())
+ continue;
- if (entry.second->GetBaseWidth() > max_entry_width)
- entry.second->SetMaximumWidth(max_entry_width);
+ accumolated_width += en->GetBaseWidth();
- max_width -= entry.second->GetBaseWidth();
- --n_entries;
- }
+ if (accumolated_width > max_width)
+ to_hide.push_back(PanelIndicatorEntryView::Ptr(en));
+ }
+
+ // No need to hide an item if there's space that we considered for the dropdown
+ if (!dropdown_->IsVisible() && to_hide.size() == 1)
+ {
+ if (accumolated_width - dropdown_->GetBaseWidth() < max_width)
+ to_hide.clear();
+ }
+
+ // There's just one hidden entries, it might fit in the space we have
+ if (to_hide.empty() && dropdown_->Size() == 1)
+ accumolated_width -= dropdown_->GetBaseWidth();
+
+ if (accumolated_width < max_width)
+ {
+ while (!dropdown_->Empty() && dropdown_->Top()->GetBaseWidth() < (max_width - accumolated_width))
+ AddEntryView(dropdown_->Pop().GetPointer());
+ }
+ else
+ {
+ for (auto const& hidden : to_hide)
+ {
+ layout_->RemoveChildObject(hidden.GetPointer());
+ RemoveChild(hidden.GetPointer());
+ dropdown_->Push(hidden);
}
}
}
@@ -129,7 +165,13 @@ PanelIndicatorEntryView* PanelIndicatorsView::ActivateEntry(std::string const& e
PanelIndicatorEntryView* view = entry->second;
if (view->IsSensitive() && view->IsVisible())
+ {
view->Activate(button);
+ }
+ else if (dropdown_)
+ {
+ dropdown_->ActivateChild(PanelIndicatorEntryView::Ptr(view));
+ }
return view;
}
@@ -139,14 +181,9 @@ PanelIndicatorEntryView* PanelIndicatorsView::ActivateEntry(std::string const& e
bool PanelIndicatorsView::ActivateIfSensitive()
{
- std::map<int, PanelIndicatorEntryView*> sorted_entries;
-
- for (auto const& entry : entries_)
- sorted_entries[entry.second->GetEntryPriority()] = entry.second;
-
- for (auto const& entry : sorted_entries)
+ for (auto* area : layout_->GetChildren())
{
- PanelIndicatorEntryView* view = entry.second;
+ auto* view = static_cast<PanelIndicatorEntryView*>(area);
if (view->IsSensitive() && view->IsVisible() && view->IsFocused())
{
@@ -176,11 +213,14 @@ PanelIndicatorEntryView* PanelIndicatorsView::ActivateEntryAt(int x, int y, int
// which causes visible lag in many cases.
//
- for (auto const& entry : entries_)
+ for (auto* area : layout_->GetChildren())
{
- PanelIndicatorEntryView* view = entry.second;
+ auto view = static_cast<PanelIndicatorEntryView*>(area);
+
+ if (!view->IsVisible())
+ continue;
- if (!target && view->IsVisible() && view->IsFocused() &&
+ if (!target && view->IsFocused() &&
view->IsSensitive() &&
view->GetAbsoluteGeometry().IsPointInside(x, y))
{
@@ -198,11 +238,11 @@ PanelIndicatorEntryView* PanelIndicatorsView::ActivateEntryAt(int x, int y, int
if (target && !found_old_active)
{
- for (auto const& entry : entries_)
+ for (auto* area : layout_->GetChildren())
{
- PanelIndicatorEntryView* view = entry.second;
+ auto view = static_cast<PanelIndicatorEntryView*>(area);
- if (view != target && view->IsActive())
+ if (view != target && view->IsVisible() && view->IsActive())
{
view->Unactivate();
break;
@@ -226,9 +266,8 @@ void PanelIndicatorsView::AddEntryView(PanelIndicatorEntryView* view, IndicatorE
return;
int entry_pos = pos;
-
+ auto const& entry_id = view->GetEntryID();
view->SetOpacity(opacity());
- view->refreshed.connect(sigc::mem_fun(this, &PanelIndicatorsView::OnEntryRefreshed));
if (entry_pos == IndicatorEntryPosition::AUTO)
{
@@ -242,20 +281,23 @@ void PanelIndicatorsView::AddEntryView(PanelIndicatorEntryView* view, IndicatorE
if (view->GetEntryPriority() <= en->GetEntryPriority())
break;
- entry_pos++;
+ ++entry_pos;
}
}
}
layout_->AddView(view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 1.0, (nux::LayoutPosition) entry_pos);
-
- entries_[view->GetEntryID()] = view;
-
AddChild(view);
+
QueueRelayout();
- QueueDraw();
- on_indicator_updated.emit(view);
+ if (entries_.find(entry_id) == entries_.end())
+ {
+ view->refreshed.connect(sigc::mem_fun(this, &PanelIndicatorsView::OnEntryRefreshed));
+ entries_.insert({entry_id, view});
+ on_indicator_updated.emit(view);
+ entry_added.emit(view);
+ }
}
PanelIndicatorEntryView *PanelIndicatorsView::AddEntry(Entry::Ptr const& entry, int padding, IndicatorEntryPosition pos, IndicatorEntryType type)
@@ -274,8 +316,6 @@ void PanelIndicatorsView::OnEntryAdded(Entry::Ptr const& entry)
void PanelIndicatorsView::OnEntryRefreshed(PanelIndicatorEntryView* view)
{
QueueRelayout();
- QueueDraw();
-
on_indicator_updated.emit(view);
}
@@ -284,14 +324,17 @@ void PanelIndicatorsView::RemoveEntryView(PanelIndicatorEntryView* view)
if (!view)
return;
- std::string const& entry_id = view->GetEntryID();
+ entry_removed.emit(view);
+
+ if (dropdown_)
+ dropdown_->Remove(PanelIndicatorEntryView::Ptr(view));
+
RemoveChild(view);
- on_indicator_updated.emit(view);
- entries_.erase(entry_id);
+ entries_.erase(view->GetEntryID());
layout_->RemoveChildObject(view);
+ on_indicator_updated.emit(view);
QueueRelayout();
- QueueDraw();
}
void PanelIndicatorsView::RemoveEntry(std::string const& entry_id)
@@ -299,11 +342,6 @@ void PanelIndicatorsView::RemoveEntry(std::string const& entry_id)
RemoveEntryView(entries_[entry_id]);
}
-void PanelIndicatorsView::OnEntryRemoved(std::string const& entry_id)
-{
- RemoveEntry(entry_id);
-}
-
void PanelIndicatorsView::OverlayShown()
{
for (auto const& entry: entries_)
diff --git a/panel/PanelIndicatorsView.h b/panel/PanelIndicatorsView.h
index 0030f2296..8067a02d9 100644
--- a/panel/PanelIndicatorsView.h
+++ b/panel/PanelIndicatorsView.h
@@ -24,9 +24,9 @@
#include <Nux/View.h>
#include <Nux/Layout.h>
-#include <UnityCore/Indicator.h>
+#include <UnityCore/Indicators.h>
-#include "PanelIndicatorEntryView.h"
+#include "PanelIndicatorEntryDropdownView.h"
#include "unity-shared/Introspectable.h"
namespace unity
@@ -67,9 +67,13 @@ public:
void SetMaximumEntriesWidth(int max_width);
void GetGeometryForSync(indicator::EntryLocationMap& locations);
+ void EnableDropdownMenu(bool, indicator::Indicators::Ptr const& i = nullptr);
+
nux::Property<double> opacity;
sigc::signal<void, PanelIndicatorEntryView*> on_indicator_updated;
+ sigc::signal<void, PanelIndicatorEntryView*> entry_added;
+ sigc::signal<void, PanelIndicatorEntryView*> entry_removed;
protected:
std::string GetName() const;
@@ -83,11 +87,9 @@ protected:
virtual void OnEntryAdded(indicator::Entry::Ptr const& entry);
virtual void OnEntryRefreshed(PanelIndicatorEntryView* view);
- virtual void OnEntryRemoved(std::string const& entry_id);
- virtual void AddEntryView(PanelIndicatorEntryView* view,
- IndicatorEntryPosition pos = AUTO);
- virtual void RemoveEntryView(PanelIndicatorEntryView* view);
+ void AddEntryView(PanelIndicatorEntryView* view, IndicatorEntryPosition pos = AUTO);
+ void RemoveEntryView(PanelIndicatorEntryView* view);
nux::HLayout* layout_;
typedef std::map<std::string, PanelIndicatorEntryView*> Entries;
@@ -97,6 +99,7 @@ private:
bool SetOpacity(double& target, double const& new_value);
Indicators indicators_;
+ PanelIndicatorEntryDropdownView::Ptr dropdown_;
std::unordered_map<indicator::Indicator::Ptr, connection::Manager> indicators_connections_;
};