From 39b0bd9b66548ba5b915be4f23ac1bb51319c8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 30 Jan 2017 14:45:08 +0100 Subject: [PATCH] [apps] Display the preferences in the title bar Change-Id: Ib1defef85b68a48f667127c583901b659db1cbaf --- apps/apps_container.cpp | 5 +++++ apps/apps_container.h | 1 + apps/apps_window.cpp | 4 ++++ apps/apps_window.h | 1 + apps/settings/sub_controller.cpp | 3 +++ apps/title_bar_view.cpp | 31 +++++++++++++++++++++++++++++-- apps/title_bar_view.h | 3 +++ 7 files changed, 46 insertions(+), 2 deletions(-) diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index cfb3d9669..d2c8599db 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -18,6 +18,7 @@ AppsContainer::AppsContainer() : m_preferences(Preferences()), m_variableBoxController(&m_globalContext) { + refreshPreferences(); } int AppsContainer::numberOfApps() { @@ -71,6 +72,10 @@ void AppsContainer::switchTo(App * app) { Container::switchTo(app); } +void AppsContainer::refreshPreferences() { + m_window.refreshPreferences(&m_preferences); +} + Window * AppsContainer::window() { return &m_window; } diff --git a/apps/apps_container.h b/apps/apps_container.h index cfa5a7219..fa1c8185c 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -29,6 +29,7 @@ public: VariableBoxController * variableBoxController(); bool handleEvent(Ion::Events::Event event) override; void switchTo(App * app) override; + void refreshPreferences(); private: Window * window() override; static constexpr int k_numberOfApps = 9; diff --git a/apps/apps_window.cpp b/apps/apps_window.cpp index daa22be70..6ef170aa4 100644 --- a/apps/apps_window.cpp +++ b/apps/apps_window.cpp @@ -18,6 +18,10 @@ void AppsWindow::updateBatteryLevel() { m_titleBarView.setChargeState(Ion::Battery::Charge::EMPTY); } +void AppsWindow::refreshPreferences(Preferences * preferences) { + m_titleBarView.setPreferences(preferences); +} + int AppsWindow::numberOfSubviews() const { return (m_contentView == nullptr ? 1 : 2); } diff --git a/apps/apps_window.h b/apps/apps_window.h index 4f05157c6..5af6c7849 100644 --- a/apps/apps_window.h +++ b/apps/apps_window.h @@ -9,6 +9,7 @@ public: AppsWindow(); void setTitle(const char * title); void updateBatteryLevel(); + void refreshPreferences(Preferences * preferences); private: constexpr static KDCoordinate k_titleBarHeight = 18; int numberOfSubviews() const override; diff --git a/apps/settings/sub_controller.cpp b/apps/settings/sub_controller.cpp index 9db5ee706..87e4583cc 100644 --- a/apps/settings/sub_controller.cpp +++ b/apps/settings/sub_controller.cpp @@ -1,4 +1,5 @@ #include "sub_controller.h" +#include "../apps_container.h" #include namespace Settings { @@ -33,6 +34,8 @@ void SubController::didBecomeFirstResponder() { bool SubController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK) { setPreferenceAtIndexWithValueIndex(m_preferenceIndex, m_selectableTableView.selectedRow()); + AppsContainer * myContainer = (AppsContainer * )app()->container(); + myContainer->refreshPreferences(); StackViewController * stack = stackController(); stack->pop(); } diff --git a/apps/title_bar_view.cpp b/apps/title_bar_view.cpp index fbaf8cd48..adf20a97e 100644 --- a/apps/title_bar_view.cpp +++ b/apps/title_bar_view.cpp @@ -5,7 +5,8 @@ extern "C" { TitleBarView::TitleBarView() : View(), - m_titleView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorWhite, Palette::YellowDark) + m_titleView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorWhite, Palette::YellowDark), + m_preferenceView(KDText::FontSize::Small, 1.0f, 0.5, KDColorWhite, Palette::YellowDark) { } @@ -23,18 +24,44 @@ void TitleBarView::setChargeState(Ion::Battery::Charge chargeState) { } int TitleBarView::numberOfSubviews() const { - return 2; + return 3; } View * TitleBarView::subviewAtIndex(int index) { if (index == 0) { return &m_titleView; } + if (index == 1) { + return &m_preferenceView; + } return &m_batteryView; } void TitleBarView::layoutSubviews() { m_titleView.setFrame(bounds()); + m_preferenceView.setFrame(KDRect(0, 0, m_preferenceView.minimalSizeForOptimalDisplay())); KDSize batterySize = m_batteryView.minimalSizeForOptimalDisplay(); m_batteryView.setFrame(KDRect(bounds().width() - batterySize.width() - k_batteryLeftMargin, (bounds().height()- batterySize.height())/2, batterySize)); } + +void TitleBarView::setPreferences(Preferences * preferences) { + char buffer[13]; + int numberOfChar = 0; + if (preferences->displayMode() == Preferences::DisplayMode::Scientific) { + strlcpy(buffer, "sci/", 5); + numberOfChar += 4; + } + if (preferences->numberType() == Preferences::NumberType::Complex) { + strlcpy(buffer+numberOfChar, "cplx/", 6); + numberOfChar += 5; + } + if (preferences->angleUnit() == Preferences::AngleUnit::Radian) { + strlcpy(buffer+numberOfChar, "rad", 4); + } else { + strlcpy(buffer+numberOfChar, "deg", 4); + } + numberOfChar += 3; + buffer[numberOfChar] = 0; + m_preferenceView.setText(buffer); + layoutSubviews(); +} diff --git a/apps/title_bar_view.h b/apps/title_bar_view.h index a0dd33e86..d93c54581 100644 --- a/apps/title_bar_view.h +++ b/apps/title_bar_view.h @@ -3,6 +3,7 @@ #include #include "battery_view.h" +#include "preferences.h" class TitleBarView : public View { public: @@ -10,6 +11,7 @@ public: void drawRect(KDContext * ctx, KDRect rect) const override; void setTitle(const char * title); void setChargeState(Ion::Battery::Charge chargeState); + void setPreferences(Preferences * preferences); private: constexpr static KDCoordinate k_batteryLeftMargin = 5; int numberOfSubviews() const override; @@ -17,6 +19,7 @@ private: View * subviewAtIndex(int index) override; PointerTextView m_titleView; BatteryView m_batteryView; + BufferTextView m_preferenceView; }; #endif