From 0d147279dc41ab41a779955f2627dde2387d5a0a Mon Sep 17 00:00:00 2001 From: Lukasz Mastalerz Date: Wed, 24 May 2023 13:55:07 +0200 Subject: [PATCH] [BH-1690] Add information about the connection to the PC Minor fixes to label positioning and connection detection --- .../presenters/StateController.cpp | 1 + .../presenter/TimeUnitsPresenter.cpp | 18 +++++--- .../BellHybrid/apps/common/CMakeLists.txt | 1 + .../layouts/HomeScreenLayoutClassic.hpp | 12 ++++-- .../common/layouts/HomeScreenLayoutNames.hpp | 24 +++++++++++ .../src/layouts/HomeScreenLayoutClassic.cpp | 25 +++++++++++ .../HomeScreenLayoutClassicWithAmPm.cpp | 6 ++- .../common/src/layouts/HomeScreenLayouts.cpp | 42 ++++++++++++------- .../src/widgets/BellConnectionStatus.cpp | 2 +- 9 files changed, 106 insertions(+), 25 deletions(-) create mode 100644 products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutNames.hpp diff --git a/products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp b/products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp index e33653c4dd0a73128821a32896232e9cfe5ece46..2d4dbb0ade1eff05d080369a2fbd4e7a4d10941b 100644 --- a/products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp +++ b/products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp @@ -367,6 +367,7 @@ namespace app::home_screen "AlarmRinging"_s + event [Helpers::isSnoozeAllowed] = "AlarmSnoozedWait"_s, "AlarmRinging"_s + event [not Helpers::isSnoozeAllowed] / Helpers::turnOffRingingAlarm = "ActivatedWait"_s, "AlarmRinging"_s + event = "AlarmRingingDeactivatedWait"_s, + "AlarmRinging"_s + event / Helpers::updateBatteryStatus, "AlarmRingingDeactivatedWait"_s + sml::on_entry<_> / AlarmRingingDeactivatedWait::entry, "AlarmRingingDeactivatedWait"_s + sml::on_exit<_> / AlarmRingingDeactivatedWait::exit, diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/TimeUnitsPresenter.cpp b/products/BellHybrid/apps/application-bell-settings/presenter/TimeUnitsPresenter.cpp index 7b5527c9e21e52bc687817d8d5cfed287d816959..536a1dd4db553784507ce0486230710d7b25881c 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/TimeUnitsPresenter.cpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/TimeUnitsPresenter.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "models/TemperatureUnitModel.hpp" @@ -6,10 +6,18 @@ #include #include +#include #include #include +namespace +{ + constexpr auto classicPrefix = "Classic"; + constexpr auto verticalPrefix = "Vertical"; + +} // namespace + namespace app::bell_settings { TimeUnitsWindowPresenter::TimeUnitsWindowPresenter( @@ -48,11 +56,11 @@ namespace app::bell_settings } if (isCurrentLayout12h) { std::string fallbackLayout; - if (currentLayout->rfind("Classic", 0) == 0) { - fallbackLayout = "Classic"; + if (currentLayout->rfind(classicPrefix, 0) == 0) { + fallbackLayout = gui::layout::Classic; } - else if (currentLayout->rfind("Vertical", 0) == 0) { - fallbackLayout = "VerticalSimple"; + else if (currentLayout->rfind(verticalPrefix, 0) == 0) { + fallbackLayout = gui::layout::VerticalSimple; } auto layoutChangeRequest = std::make_shared(fallbackLayout); app->bus.sendUnicast(layoutChangeRequest, service::name::appmgr); diff --git a/products/BellHybrid/apps/common/CMakeLists.txt b/products/BellHybrid/apps/common/CMakeLists.txt index ebdb41c63447ba609c7c65e2d5c9c52d1afab67f..2622e32ccd5624d67b62d3491941d7372c13d546 100644 --- a/products/BellHybrid/apps/common/CMakeLists.txt +++ b/products/BellHybrid/apps/common/CMakeLists.txt @@ -123,6 +123,7 @@ target_sources(application-bell-common include/common/layouts/HomeScreenLayoutVerticalSimple.hpp include/common/layouts/HomeScreenLayoutVerticalWithAmPm.hpp include/common/layouts/HomeScreenLayoutVerticalWithDate.hpp + include/common/layouts/HomeScreenLayoutNames.hpp ) target_link_libraries(application-bell-common diff --git a/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassic.hpp b/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassic.hpp index de581a309f050fa376a3c5c7461b983f5d4c712b..c401ba05464d7a58c041e4197cbb23ea034069db 100644 --- a/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassic.hpp +++ b/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassic.hpp @@ -9,9 +9,11 @@ namespace style::homescreen_classic { - constexpr inline auto status_box_layout_w = 350U; - constexpr inline auto info_box_layout_h = 70U; - constexpr inline auto connection_box_layout_h = 44U; + constexpr inline auto status_box_layout_w = 350U; + constexpr inline auto info_box_layout_h = 70U; + constexpr inline auto connection_box_layout_h = 44U; + constexpr inline auto connection_box_top_margin = 20U; + constexpr inline auto connection_box_bottom_margin = -20; } // namespace style::homescreen_classic namespace gui @@ -68,6 +70,10 @@ namespace gui virtual bool isBatteryVisibilityAllowed(const Store::Battery &batteryContext); void removeTextDescription(); + private: + void adjustConnectionStatusPosition(); + + protected: VBox *widgetBox = nullptr; HBox *timeHBox = nullptr; TimeSetFmtSpinner *time = nullptr; diff --git a/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutNames.hpp b/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutNames.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b891aac61d5b9bced62bc4327a5c7c809d4fc541 --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutNames.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +namespace gui +{ + namespace layout + { + constexpr auto Classic = "Classic"; + constexpr auto ClassicWithBattery = "ClassicWithBattery"; + constexpr auto ClassicWithAmPm = "ClassicWithAmPm"; + constexpr auto ClassicWithDate = "ClassicWithDate"; + constexpr auto VerticalSimple = "VerticalSimple"; + constexpr auto VerticalWithDate = "VerticalWithDate"; + constexpr auto VerticalWithAmPm = "VerticalWithAmPm"; + constexpr auto VerticalWithDateAmPm = "VerticalWithDateAmPm"; + +#if CONFIG_ENABLE_TEMP == 1 + constexpr auto ClassicWithTemp = "ClassicWithTemp"; +#endif + + } // namespace layout +} // namespace gui diff --git a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp index 66e0412229f8c38660ab701d824db6fbb6434a16..eae81c1e985f4e55e5cf17779f4494e6a956475f 100644 --- a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp +++ b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp @@ -2,6 +2,7 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "layouts/HomeScreenLayoutClassic.hpp" +#include "layouts/HomeScreenLayoutNames.hpp" #include "data/BellMainStyle.hpp" #include "widgets/BellBattery.hpp" #include "widgets/BellConnectionStatus.hpp" @@ -247,6 +248,7 @@ namespace gui } battery->informContentChanged(); connectionStatus->informContentChanged(); + adjustConnectionStatusPosition(); } void HomeScreenLayoutClassic::setTime(std::time_t newTime) @@ -301,4 +303,27 @@ namespace gui connectionStatus->setConnected(); connectionStatus->informContentChanged(); } + + auto HomeScreenLayoutClassic::adjustConnectionStatusPosition() -> void + { + if (getName() == gui::layout::Classic) { + if (battery->visible) { + widgetBox->removeWidget(infoBox); + widgetBox->removeWidget(connectionBox); + connectionBox->setMargins(Margins(0, 0, 0, 0)); + widgetBox->addWidget(infoBox); + widgetBox->addWidget(connectionBox); + } + else { + widgetBox->removeWidget(infoBox); + widgetBox->removeWidget(connectionBox); + connectionBox->setMargins(Margins(0, + style::homescreen_classic::connection_box_top_margin, + 0, + style::homescreen_classic::connection_box_bottom_margin)); + widgetBox->addWidget(connectionBox); + widgetBox->addWidget(infoBox); + } + } + } }; // namespace gui diff --git a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassicWithAmPm.cpp b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassicWithAmPm.cpp index 4386e6087d4f85deb1e48af59f4f5cb9c55cb7ea..b63af52d6b7dcef828d125a1b2c88adb11cbb81c 100644 --- a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassicWithAmPm.cpp +++ b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassicWithAmPm.cpp @@ -23,7 +23,7 @@ namespace gui battery->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); - fmt = new TextFixedSize(infoBox); + fmt = new TextFixedSize(nullptr); fmt->setMaximumSize(style::homescreen_classic::status_box_layout_w, style::bell_base_layout::outer_layouts_h); fmt->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); fmt->setFont(mainWindow::bottomDescription::font_normal); @@ -32,6 +32,10 @@ namespace gui fmt->drawUnderline(false); fmt->setText(""); fmt->setMargins({0, style::bell_base_layout::info_box_top_margin, 0, 0}); + + infoBox->removeWidget(battery); + infoBox->addWidget(battery); + infoBox->addWidget(fmt); } auto HomeScreenLayoutClassicWithAmPm::setTime(std::time_t newTime) -> void diff --git a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayouts.cpp b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayouts.cpp index 3c02dc23f9c779c23131169a7a67d780d3e76f0d..95c1040909cf1a212bd6b19d8f9c9841388eb6e0 100644 --- a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayouts.cpp +++ b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayouts.cpp @@ -1,7 +1,8 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md +#include #include #include #include @@ -21,17 +22,22 @@ namespace gui::factory { return { - {"Classic", []() { return new HomeScreenLayoutClassic("Classic"); }}, - {"ClassicWithBattery", []() { return new HomeScreenLayoutClassicWithBattery("ClassicWithBattery"); }}, - {"ClassicWithDate", []() { return new HomeScreenLayoutClassicWithDate("ClassicWithDate"); }}, - {"VerticalSimple", []() { return new HomeScreenLayoutVerticalSimple("VerticalSimple"); }}, + {gui::layout::Classic, []() { return new HomeScreenLayoutClassic(gui::layout::Classic); }}, + {gui::layout::ClassicWithBattery, + []() { return new HomeScreenLayoutClassicWithBattery(gui::layout::ClassicWithBattery); }}, + {gui::layout::ClassicWithDate, + []() { return new HomeScreenLayoutClassicWithDate(gui::layout::ClassicWithDate); }}, + {gui::layout::VerticalSimple, + []() { return new HomeScreenLayoutVerticalSimple(gui::layout::VerticalSimple); }}, { - "VerticalWithDate", []() { return new HomeScreenLayoutVerticalWithDate("VerticalWithDate"); } + gui::layout::VerticalWithDate, + []() { return new HomeScreenLayoutVerticalWithDate(gui::layout::VerticalWithDate); } } #if CONFIG_ENABLE_TEMP == 1 , { - "ClassicWithTemp", []() { return new HomeScreenLayoutClassicWithTemp("ClassicWithTemp"); } + gui::layout::ClassicWithTemp, + []() { return new HomeScreenLayoutClassicWithTemp(gui::layout::ClassicWithTemp); } } #endif }; @@ -41,14 +47,20 @@ namespace gui::factory { return { - {"Classic", []() { return new HomeScreenLayoutClassic("Classic"); }}, - {"ClassicWithAmPm", []() { return new HomeScreenLayoutClassicWithAmPm("ClassicWithAmPm"); }}, - {"ClassicWithBattery", []() { return new HomeScreenLayoutClassicWithBattery("ClassicWithBattery"); }}, - {"ClassicWithDate", []() { return new HomeScreenLayoutClassicWithDate("ClassicWithDateAmPm"); }}, - {"VerticalSimple", []() { return new HomeScreenLayoutVerticalSimple("VerticalSimple"); }}, - {"VerticalWithAmPm", []() { return new HomeScreenLayoutVerticalWithAmPm("VerticalWithAmPm"); }}, + {gui::layout::Classic, []() { return new HomeScreenLayoutClassic(gui::layout::Classic); }}, + {gui::layout::ClassicWithAmPm, + []() { return new HomeScreenLayoutClassicWithAmPm(gui::layout::ClassicWithAmPm); }}, + {gui::layout::ClassicWithBattery, + []() { return new HomeScreenLayoutClassicWithBattery(gui::layout::ClassicWithBattery); }}, + {gui::layout::ClassicWithDate, + []() { return new HomeScreenLayoutClassicWithDate(gui::layout::ClassicWithDate); }}, + {gui::layout::VerticalSimple, + []() { return new HomeScreenLayoutVerticalSimple(gui::layout::VerticalSimple); }}, + {gui::layout::VerticalWithAmPm, + []() { return new HomeScreenLayoutVerticalWithAmPm(gui::layout::VerticalWithAmPm); }}, { - "VerticalWithDate", []() { return new HomeScreenLayoutVerticalWithDate("VerticalWithDateAmPm"); } + gui::layout::VerticalWithDate, + []() { return new HomeScreenLayoutVerticalWithDate(gui::layout::VerticalWithDateAmPm); } } #if CONFIG_ENABLE_TEMP == 1 , @@ -66,7 +78,7 @@ namespace gui::factory std::string getDefaultLayout() { - return "ClassicWithBattery"; + return gui::layout::ClassicWithBattery; } } // namespace gui::factory diff --git a/products/BellHybrid/apps/common/src/widgets/BellConnectionStatus.cpp b/products/BellHybrid/apps/common/src/widgets/BellConnectionStatus.cpp index 69d759546a74aba2831af5a7a2501432d699bdc3..026a233b29268ada7509ff18aaf18faaf136bf57 100644 --- a/products/BellHybrid/apps/common/src/widgets/BellConnectionStatus.cpp +++ b/products/BellHybrid/apps/common/src/widgets/BellConnectionStatus.cpp @@ -37,7 +37,7 @@ namespace gui void BellConnectionStatus::checkIfConnected(const Store::Battery::State &state) { - if (state == Store::Battery::State::Discharging) { + if (state != Store::Battery::State::PluggedNotCharging) { statusText->setVisible(false); } }