From 87ed83ca5ce1209cd4591fc58d16e441928b147c Mon Sep 17 00:00:00 2001 From: Mateusz Grzegorzek Date: Tue, 10 Aug 2021 15:56:05 +0200 Subject: [PATCH] [BH-701] Use TimeSetFmtSpinner in Alarm app Use TimeSetFmtSpinner in Alarm app --- .../ApplicationBellAlarm.cpp | 4 ++- .../application-bell-alarm/CMakeLists.txt | 3 ++ .../data/BellAlarmStyle.hpp | 15 +++++++++ .../presenter/BellAlarmWindowPresenter.cpp | 12 +++++++ .../presenter/BellAlarmWindowPresenter.hpp | 33 +++++++++++++++++++ .../windows/BellAlarmWindow.cpp | 25 +++++++++++++- .../windows/BellAlarmWindow.hpp | 14 ++++++-- module-gui/gui/widgets/Spinner.cpp | 1 + module-gui/gui/widgets/Spinner.hpp | 4 +-- module-gui/gui/widgets/TextFixedSize.cpp | 3 ++ module-gui/gui/widgets/TextFixedSize.hpp | 1 + 11 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 module-apps/application-bell-alarm/data/BellAlarmStyle.hpp create mode 100644 module-apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.cpp create mode 100644 module-apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.hpp diff --git a/module-apps/application-bell-alarm/ApplicationBellAlarm.cpp b/module-apps/application-bell-alarm/ApplicationBellAlarm.cpp index 2f92e7da2b890b287f384a406b0f5de8fc313c53..320261ca282acd590dab64041cacca5af129986d 100644 --- a/module-apps/application-bell-alarm/ApplicationBellAlarm.cpp +++ b/module-apps/application-bell-alarm/ApplicationBellAlarm.cpp @@ -2,6 +2,7 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include +#include #include namespace app @@ -28,7 +29,8 @@ namespace app void ApplicationBellAlarm::createUserInterface() { windowsFactory.attach(gui::name::window::main_window, [](Application *app, const std::string &name) { - return std::make_unique(app); + auto presenter = std::make_unique(); + return std::make_unique(app, std::move(presenter)); }); } diff --git a/module-apps/application-bell-alarm/CMakeLists.txt b/module-apps/application-bell-alarm/CMakeLists.txt index fd931027912f12487d36cdd04cede546b3566456..c77890429e3157d22d645e6949e2089ec552b882 100644 --- a/module-apps/application-bell-alarm/CMakeLists.txt +++ b/module-apps/application-bell-alarm/CMakeLists.txt @@ -3,8 +3,11 @@ add_library(application-bell-alarm) target_sources(application-bell-alarm PRIVATE ApplicationBellAlarm.cpp + presenter/BellAlarmWindowPresenter.cpp windows/BellAlarmWindow.cpp PRIVATE + data/BellAlarmStyle.hpp + presenter/BellAlarmWindowPresenter.hpp windows/BellAlarmWindow.hpp PUBLIC include/application-bell-alarm/ApplicationBellAlarm.hpp diff --git a/module-apps/application-bell-alarm/data/BellAlarmStyle.hpp b/module-apps/application-bell-alarm/data/BellAlarmStyle.hpp new file mode 100644 index 0000000000000000000000000000000000000000..11acde54cd8e40712af3ad4f8b7f7f6fd72b4fe9 --- /dev/null +++ b/module-apps/application-bell-alarm/data/BellAlarmStyle.hpp @@ -0,0 +1,15 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +namespace gui +{ + namespace bell_alarm_style + { + namespace time_set_fmt_spinner + { + inline constexpr auto font = "gt_pressura_regular_90"; + } // namespace time_set_fmt_spinner + } // namespace bell_alarm_style +} // namespace gui diff --git a/module-apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.cpp b/module-apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b9a3e8ea185149ac5223ebb6e993165c214e318 --- /dev/null +++ b/module-apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.cpp @@ -0,0 +1,12 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "BellAlarmWindowPresenter.hpp" + +namespace app::bell_alarm +{ + auto BellAlarmWindowPresenter::saveData() -> void + { + // TODO + } +} // namespace app::bell_alarm diff --git a/module-apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.hpp b/module-apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3c1dff1bb296a921f5d6ad93fa55c6d739244d7f --- /dev/null +++ b/module-apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.hpp @@ -0,0 +1,33 @@ + +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +namespace app::bell_alarm +{ + class BellAlarmWindowContract + { + public: + class View + { + public: + virtual ~View() noexcept = default; + }; + + class Presenter : public BasePresenter + { + public: + virtual ~Presenter() noexcept = default; + virtual auto saveData() -> void = 0; + }; + }; + + class BellAlarmWindowPresenter : public BellAlarmWindowContract::Presenter + { + public: + auto saveData() -> void override; + }; +} // namespace app::bell_alarm diff --git a/module-apps/application-bell-alarm/windows/BellAlarmWindow.cpp b/module-apps/application-bell-alarm/windows/BellAlarmWindow.cpp index 3e08d88bffed366a5b5c22e686021d90ea58eec5..26af4bb7f75fab77a147c4b368001a572986cd92 100644 --- a/module-apps/application-bell-alarm/windows/BellAlarmWindow.cpp +++ b/module-apps/application-bell-alarm/windows/BellAlarmWindow.cpp @@ -3,25 +3,48 @@ #include "BellAlarmWindow.hpp" +#include +#include +#include #include namespace gui { - BellAlarmWindow::BellAlarmWindow(app::Application *app, std::string name) : AppWindow(app, std::move(name)) + BellAlarmWindow::BellAlarmWindow( + app::Application *app, + std::unique_ptr &&windowPresenter, + std::string name) + : AppWindow(app, std::move(name)), presenter{std::move(windowPresenter)} { + presenter->attach(this); buildInterface(); } void BellAlarmWindow::buildInterface() { AppWindow::buildInterface(); + statusBar->setVisible(false); header->setTitleVisibility(true); bottomBar->setVisible(false); + + body = new BellBaseLayout(this, 0, 0, style::window_width, style::window_height); + timeSetFmtSpinner = new TimeSetFmtSpinner(body->centerBox); + timeSetFmtSpinner->setFont(bell_alarm_style::time_set_fmt_spinner::font); + + setFocusItem(body); } bool BellAlarmWindow::onInput(const InputEvent &inputEvent) { + if (body->onInput(inputEvent)) { + return true; + } + if (inputEvent.isShortRelease(KeyCode::KEY_ENTER)) { + presenter->saveData(); + application->returnToPreviousWindow(); + return true; + } return AppWindow::onInput(inputEvent); } diff --git a/module-apps/application-bell-alarm/windows/BellAlarmWindow.hpp b/module-apps/application-bell-alarm/windows/BellAlarmWindow.hpp index c573abf1d992564daa934fe91b10951762599336..daa947e19d4349951947205535419c0dd0b4d949 100644 --- a/module-apps/application-bell-alarm/windows/BellAlarmWindow.hpp +++ b/module-apps/application-bell-alarm/windows/BellAlarmWindow.hpp @@ -4,18 +4,28 @@ #pragma once #include +#include #include namespace gui { - class BellAlarmWindow : public AppWindow + class BellBaseLayout; + class TimeSetFmtSpinner; + class BellAlarmWindow : public AppWindow, public app::bell_alarm::BellAlarmWindowContract::View { public: - explicit BellAlarmWindow(app::Application *app, std::string name = window::name::bellAlarm); + explicit BellAlarmWindow(app::Application *app, + std::unique_ptr &&windowPresenter, + std::string name = window::name::bellAlarm); void buildInterface() override; bool onInput(const InputEvent &inputEvent) override; void rebuild() override; + + private: + BellBaseLayout *body{nullptr}; + TimeSetFmtSpinner *timeSetFmtSpinner{nullptr}; + std::unique_ptr presenter; }; } /* namespace gui */ diff --git a/module-gui/gui/widgets/Spinner.cpp b/module-gui/gui/widgets/Spinner.cpp index 0179b1ab3e1778c3baa7244ac233030a1239f26f..f2b65cdb88a16f308c9b6e7e3c7a152545835fba 100644 --- a/module-gui/gui/widgets/Spinner.cpp +++ b/module-gui/gui/widgets/Spinner.cpp @@ -15,6 +15,7 @@ namespace gui : minValue(minValue), maxValue(maxValue), step(step), currentValue(minValue), boundaries(boundaries) { setEditMode(EditMode::Browse); + drawUnderline(false); updateSpinner(); } diff --git a/module-gui/gui/widgets/Spinner.hpp b/module-gui/gui/widgets/Spinner.hpp index 76c7bb55b939f7a7b45bfa95b1431809cc50b3fd..cede8e43cae8326c0b3eaec60232e8a6c82eea9b 100644 --- a/module-gui/gui/widgets/Spinner.hpp +++ b/module-gui/gui/widgets/Spinner.hpp @@ -3,11 +3,11 @@ #pragma once -#include "Text.hpp" +#include "TextFixedSize.hpp" namespace gui { - class Spinner : public Text + class Spinner : public TextFixedSize { public: Spinner(int minValue, int maxValue, int step, Boundaries boundaries); diff --git a/module-gui/gui/widgets/TextFixedSize.cpp b/module-gui/gui/widgets/TextFixedSize.cpp index 8e78295b6f3795db309939710fd871eb72c4b603..72f49bfad8e42dca8cf8bae3a385463974be9263 100644 --- a/module-gui/gui/widgets/TextFixedSize.cpp +++ b/module-gui/gui/widgets/TextFixedSize.cpp @@ -7,6 +7,9 @@ namespace gui { + TextFixedSize::TextFixedSize() : TextFixedSize(nullptr, 0, 0, 0, 0) + {} + TextFixedSize::TextFixedSize(Item *parent, Position x, Position y, Length w, Length h) : Text(parent, x, y, w, h) { setEditMode(EditMode::Edit); diff --git a/module-gui/gui/widgets/TextFixedSize.hpp b/module-gui/gui/widgets/TextFixedSize.hpp index da29ea72b98dfafc6cc0a7bcf3173e2aa69e9657..27290e86b095b9d60e10381eb9be72eb1e94480c 100644 --- a/module-gui/gui/widgets/TextFixedSize.hpp +++ b/module-gui/gui/widgets/TextFixedSize.hpp @@ -16,6 +16,7 @@ namespace gui void drawLines() override; public: + TextFixedSize(); TextFixedSize(Item *parent, Position x, Position y, Length w, Length h); void setLines(unsigned int val);