diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-02-17 05:01:26 +0100 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-02-17 05:01:26 +0100 |
| commit | d88a9c6ab2ca9a429af88c895807b0f1b58cddf5 (patch) | |
| tree | 0f42df3bdcedcba59b03a25c50fcf2ce398517a0 /unity-shared | |
| parent | 53262d60d7a7afcda0e97f1488fa0457fc959743 (diff) | |
SpreadFilter: a BaseWindow with a SearchBar that is shown/hidden when there's some content
The SpreadFilter is a SearchBar shown on the top-left corner of the active workspace that is hidden by default monitoring key-presses; when some content is put the bar is shown, while is hidden when empty. (bzr r3656.5.3)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | unity-shared/SpreadFilter.cpp | 110 | ||||
| -rw-r--r-- | unity-shared/SpreadFilter.h | 64 |
3 files changed, 175 insertions, 0 deletions
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index c6b20fb66..5fca6ab17 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -55,6 +55,7 @@ set (UNITY_SHARED_SOURCES ResizingBaseWindow.cpp SearchBar.cpp SearchBarSpinner.cpp + SpreadFilter.cpp StaticCairoText.cpp TextureCache.cpp TextInput.cpp diff --git a/unity-shared/SpreadFilter.cpp b/unity-shared/SpreadFilter.cpp new file mode 100644 index 000000000..508d613c9 --- /dev/null +++ b/unity-shared/SpreadFilter.cpp @@ -0,0 +1,110 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (C) 2014 Canonical Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 3 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* Authored by: Marco Trevisan <marco@ubuntu.com> +*/ + +#include "SpreadFilter.h" + +#include <Nux/HLayout.h> +#include "AnimationUtils.h" +#include "SearchBar.h" +#include "WindowManager.h" + +namespace unity +{ +namespace spread +{ +namespace +{ +const unsigned FADE_DURATION = 100; +const nux::Point OFFSET(10, 15); +const nux::Size SIZE(620, 42); +} + +Filter::Filter() + : fade_animator_(FADE_DURATION) +{ + search_bar_ = SearchBar::Ptr(new SearchBar()); + search_bar_->SetMinMaxSize(SIZE.width, SIZE.height); + text.SetGetterFunction([this] { return search_bar_->search_string(); }); + text.SetSetterFunction([this] (std::string const& t) { search_bar_->search_string = t; return false; }); + debug::Introspectable::AddChild(search_bar_.GetPointer()); + + auto layout = new nux::HLayout(NUX_TRACKER_LOCATION); + layout->SetVerticalExternalMargin(0); + layout->SetHorizontalExternalMargin(0); + layout->AddView(search_bar_.GetPointer()); + + auto const& work_area = WindowManager::Default().GetWorkAreaGeometry(0); + view_window_ = new nux::BaseWindow(GetName().c_str()); + view_window_->SetLayout(layout); + view_window_->SetBackgroundColor(nux::color::Transparent); + view_window_->SetWindowSizeMatchLayout(true); + view_window_->ShowWindow(true); + view_window_->PushToFront(); + view_window_->SetOpacity(0.0f); + view_window_->SetEnterFocusInputArea(search_bar_.GetPointer()); + view_window_->SetInputFocus(); + view_window_->SetXY(OFFSET.x + work_area.x, OFFSET.y + work_area.y); + fade_animator_.updated.connect([this] (double opacity) { view_window_->SetOpacity(opacity); }); + + nux::GetWindowCompositor().SetKeyFocusArea(search_bar_->text_entry()); + + search_bar_->live_search_reached.connect([this] (std::string const& search) { + if (!Visible()) + animation::StartOrReverse(fade_animator_, animation::Direction::FORWARD); + + text.changed.emit(search); + search_bar_->SetSearchFinished(); + + if (search.empty()) + animation::StartOrReverse(fade_animator_, animation::Direction::BACKWARD); + }); +} + +Filter::~Filter() +{ + nux::GetWindowCompositor().SetKeyFocusArea(nullptr); + nux::GetWindowThread()->RemoveObjectFromLayoutQueue(view_window_.GetPointer()); +} + +bool Filter::Visible() const +{ + return (view_window_->GetOpacity() != 0.0f); +} + +nux::Geometry const& Filter::GetAbsoluteGeometry() const +{ + return view_window_->GetGeometry(); +} + +// +// Introspection +// +std::string Filter::GetName() const +{ + return "SpreadFilter"; +} + +void Filter::AddProperties(debug::IntrospectionData& introspection) +{ + introspection + .add("visible", Visible()); +} + +} // namespace spread +} // namespace unity diff --git a/unity-shared/SpreadFilter.h b/unity-shared/SpreadFilter.h new file mode 100644 index 000000000..2709315a5 --- /dev/null +++ b/unity-shared/SpreadFilter.h @@ -0,0 +1,64 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (C) 2014 Canonical Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 3 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* Authored by: Marco Trevisan <marco@ubuntu.com> +*/ + +#ifndef UNITYSHELL_SPREAD_FILTER_H +#define UNITYSHELL_SPREAD_FILTER_H + +#include <memory> + +#include <Nux/Nux.h> +#include <Nux/BaseWindow.h> +#include <NuxCore/Animation.h> +#include "Introspectable.h" + +namespace unity +{ +class SearchBar; + +namespace spread +{ + +class Filter : public debug::Introspectable, public sigc::trackable +{ +public: + typedef std::shared_ptr<Filter> Ptr; + + Filter(); + virtual ~Filter(); + + nux::RWProperty<std::string> text; + + bool Visible() const; + nux::Geometry const& GetAbsoluteGeometry() const; + +protected: + // Introspectable + std::string GetName() const; + void AddProperties(debug::IntrospectionData&); + +private: + nux::ObjectPtr<SearchBar> search_bar_; + nux::ObjectPtr<nux::BaseWindow> view_window_; + nux::animation::AnimateValue<double> fade_animator_; +}; + +} // namespace spread +} // namespace unity + +#endif |
