Cursor color page in MVP 18/207118/5
authorOskar Chodowicz <o.chodowicz@samsung.com>
Thu, 30 May 2019 07:00:16 +0000 (09:00 +0200)
committerOskar Chodowicz <o.chodowicz@samsung.com>
Tue, 25 Jun 2019 13:40:17 +0000 (15:40 +0200)
Change-Id: I4dc6f95bd2809990b63f6943d146b7a66ad7259d

src/model/CursorColorModel.cpp [new file with mode: 0644]
src/model/CursorColorModel.hpp [new file with mode: 0644]
src/model/UniversalSwitchSettingsPageModel.cpp
src/model/UniversalSwitchSettingsPageModel.hpp
src/presenter/CursorColorPagePresenter.cpp [new file with mode: 0644]
src/presenter/CursorColorPagePresenter.hpp [new file with mode: 0644]
src/presenter/UniversalSwitchSettingsPagePresenter.cpp
src/presenter/UniversalSwitchSettingsPagePresenter.hpp
src/utils/Geometry.cpp

diff --git a/src/model/CursorColorModel.cpp b/src/model/CursorColorModel.cpp
new file mode 100644 (file)
index 0000000..383234e
--- /dev/null
@@ -0,0 +1,34 @@
+#include "CursorColorModel.hpp"
+
+#include "UniversalSwitchConstants.hpp"
+
+CursorColorModel::CursorColorModel()
+{
+       vconfHandle_ = Singleton<VConfInterface>::instance().registerAndGet<int>(
+               VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_CURSOR_COLOR,
+               DEFAULT_FEEDBACK_CURSOR_COLOR,
+               [this](auto value) {
+                       this->cursorColor_ = Color::fromABGR(value);
+               });
+       cursorColor_.attach([this](auto value) {
+               Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_CURSOR_COLOR, value.toABGRInt());
+       });
+}
+
+std::string CursorColorModel::getColorText(Color color)
+{
+       if (color == Color::RED)
+               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_RED";
+       if (color == Color::ORANGE)
+               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_ORANGE";
+       if (color == Color::YELLOW)
+               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_YELLOW";
+       if (color == Color::GREEN)
+               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_GREEN";
+       if (color == Color::BLUE)
+               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_BLUE";
+       if (color == Color::GRAY)
+               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_GRAY";
+
+       return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_UNDEFINED";
+}
\ No newline at end of file
diff --git a/src/model/CursorColorModel.hpp b/src/model/CursorColorModel.hpp
new file mode 100644 (file)
index 0000000..58c0a2a
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef CURSOR_COLOR_MODEL_HPP
+#define CURSOR_COLOR_MODEL_HPP
+
+#include "Geometry.hpp"
+#include "ObservableProperty.hpp"
+#include "VConf.hpp"
+
+class CursorColorModel
+{
+       public:
+       CursorColorModel();
+       ObservableProperty<Color> cursorColor_;
+       std::string getColorText(Color color);
+
+       private:
+       VConfInterface::CallbackHandle vconfHandle_;
+};
+
+#endif
\ No newline at end of file
index 40f3231..9625a59 100644 (file)
@@ -8,17 +8,6 @@ UniversalSwitchSettingsPageModel::UniversalSwitchSettingsPageModel()
        synchronizePropertyWithVConf(scanDirection_, VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SCAN_DIR_VERTICAL, DEFAULT_SCAN_DIR);
        synchronizePropertyWithVConf(autoTapKeyboardState_, VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_TAP_KBD_STATE, DEFAULT_AUTO_TAP_KEYBOARD_STATE);
 
-       vconfHandles_.push_back(Singleton<VConfInterface>::instance().registerAndGet<int>(
-               VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_CURSOR_COLOR,
-               DEFAULT_FEEDBACK_CURSOR_COLOR,
-               [this](auto value) {
-                       cursorColor_ = Color::fromABGR(value);
-               }));
-
-       cursorColor_.attach([this](auto newValue) {
-               Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_CURSOR_COLOR, newValue.toABGRInt());
-       });
-
        connectionPtr_ = DBus::getDBusConnectionByType(DBus::ConnectionType::SESSION);
        dBusClient_ = DBus::DBusClient{BUS, PATH, IFACE, connectionPtr_};
        auto reply = dBusClient_.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string, int32_t>>>()>("getAllSwitchConfigurationItems").call();
index da4a228..1024df1 100644 (file)
@@ -18,8 +18,6 @@ class UniversalSwitchSettingsPageModel
        ObservableProperty<ScanDirection> scanDirection_;
        ObservableProperty<bool> autoTapKeyboardState_;
 
-       ObservableProperty<Color> cursorColor_;
-
        private:
        template <typename T>
        void synchronizePropertyWithVConf(ObservableProperty<T> &property, const std::string &vconfKey, T defaultValue)
diff --git a/src/presenter/CursorColorPagePresenter.cpp b/src/presenter/CursorColorPagePresenter.cpp
new file mode 100644 (file)
index 0000000..ca1df8b
--- /dev/null
@@ -0,0 +1,23 @@
+#include "CursorColorPagePresenter.hpp"
+
+#include "AppContext.hpp"
+
+CursorColorPagePresenter::CursorColorPagePresenter()
+{
+       setTitle("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL");
+       groups_.emplace_back("");
+       auto &items = groups_.back().items_;
+       for (auto color : colors_) {
+               items.push_back(std::make_unique<ListItem>(
+                       model_.getColorText(color),
+                       std::string{},
+                       [this, color](auto item) {
+                               this->model_.cursorColor_ = color;
+                               Singleton<AppContext>::instance().pop();
+                       },
+                       ListItem::WidgetType::radio,
+                       std::function<void(ListItem * item)>{},
+                       std::function<void(ListItem * item)>{},
+                       color == model_.cursorColor_.value()));
+       }
+}
\ No newline at end of file
diff --git a/src/presenter/CursorColorPagePresenter.hpp b/src/presenter/CursorColorPagePresenter.hpp
new file mode 100644 (file)
index 0000000..b07594a
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef CURSOR_COLOR_PAGE_PRESENTER_HPP
+#define CURSOR_COLOR_PAGE_PRESENTER_HPP
+
+#include "CursorColorModel.hpp"
+#include "ListPresenter.hpp"
+
+#include <vector>
+
+class CursorColorPagePresenter : public ListPresenter
+{
+       public:
+       CursorColorPagePresenter();
+
+       private:
+       CursorColorModel model_;
+       std::vector<Color> colors_ = {
+               Color::RED,
+               Color::ORANGE,
+               Color::YELLOW,
+               Color::GREEN,
+               Color::BLUE,
+               Color::GRAY};
+};
+
+#endif
\ No newline at end of file
index af32d40..f2ea22b 100644 (file)
@@ -4,6 +4,7 @@
 #include "AutoMoveIntervalPresenter.hpp"
 #include "AutoScanIntervalPresenter.hpp"
 #include "AutoTapPresenter.hpp"
+#include "CursorColorPagePresenter.hpp"
 #include "ManageMenuOptionsPagePresenter.hpp"
 #include "NumberOfAutoScanLoopsPresenter.hpp"
 #include "PauseOnFirstPresenter.hpp"
@@ -271,13 +272,13 @@ void UniversalSwitchSettingsPagePresenter::createFeedbackGroup()
 
        items.push_back(std::make_unique<ListItem>(
                std::string{"IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL"},
-               getColorText(model_.cursorColor_.value()),
+               cursorColorModel_.getColorText(cursorColorModel_.cursorColor_.value()),
                [this](auto item) {
-                       DEBUG("cursor color widget");
+                       Singleton<AppContext>::instance().push(std::make_unique<CursorColorPagePresenter>());
                }));
        auto item = items.back().get();
-       model_.cursorColor_.attach([item, this](auto value) {
-               item->description_ = getColorText(value);
+       cursorColorModel_.cursorColor_.attach([item, this](auto value) {
+               item->description_ = this->cursorColorModel_.getColorText(value);
        });
 
        items.push_back(std::make_unique<ListItem>(
@@ -373,21 +374,3 @@ std::string UniversalSwitchSettingsPagePresenter::getScanMethodText(ScanMethod s
                return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_UNDEFINED";
        }
 }
-
-std::string UniversalSwitchSettingsPagePresenter::getColorText(Color color)
-{
-       if (color == Color::RED)
-               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_RED";
-       if (color == Color::ORANGE)
-               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_ORANGE";
-       if (color == Color::YELLOW)
-               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_YELLOW";
-       if (color == Color::GREEN)
-               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_GREEN";
-       if (color == Color::BLUE)
-               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_BLUE";
-       if (color == Color::GRAY)
-               return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_CURSOR_CL_GRAY";
-
-       return "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_UNDEFINED";
-}
index 5f83fe1..6489159 100644 (file)
@@ -4,6 +4,7 @@
 #include "AutoMoveIntervalModel.hpp"
 #include "AutoScanModel.hpp"
 #include "AutoTapModel.hpp"
+#include "CursorColorModel.hpp"
 #include "ListPresenter.hpp"
 #include "NumberOfAutoScanLoopsModel.hpp"
 #include "PauseOnFirstModel.hpp"
@@ -27,7 +28,6 @@ class UniversalSwitchSettingsPagePresenter : public ListPresenter
        void createFeedbackGroup();
        static std::string getScanDirectionText(ScanDirection scanDirection);
        static std::string getScanMethodText(ScanMethod scanMethod);
-       static std::string getColorText(Color color);
 
        UniversalSwitchSettingsPageModel model_;
        AutoScanModel autoScanModel_;
@@ -40,6 +40,7 @@ class UniversalSwitchSettingsPagePresenter : public ListPresenter
        AutoMoveIntervalModel autoMoveIntervalModel_;
        SoundModel soundModel_;
        VoiceModel voiceModel_;
+       CursorColorModel cursorColorModel_;
 
        std::unique_ptr<SwitchesPage> switchesPage_;
 };
index 2614597..4f1aea1 100644 (file)
@@ -101,7 +101,7 @@ int Color::toRGBAInt() const
 
 int Color::toABGRInt() const
 {
-       return (a << 24) | (b << 16) | (r << 8) | g;
+       return (a << 24) | (b << 16) | (g << 8) | r;
 }
 
 Color Color::invert() const