Add new type of GenlistItem - Icon 65/200865/9
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 5 Mar 2019 07:32:58 +0000 (08:32 +0100)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Thu, 7 Mar 2019 08:04:36 +0000 (09:04 +0100)
This change introduce new type of GenlistItem
and use it in SwitchesPage

Change-Id: I76a7d4303da2aad76d75492a0466005e6563e909

src/GenlistItem.cpp
src/GenlistItem.hpp
src/Icon.cpp
src/Icon.hpp
src/SwitchesPage.cpp
src/SwitchesPage.hpp
src/Widget.cpp
src/Widget.hpp

index df1e612..6db26a3 100644 (file)
@@ -3,6 +3,7 @@
 #include "setting-debug.h"
 #include "Check.hpp"
 #include "Genlist.hpp"
+#include "Icon.hpp"
 
 GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, Type type)
        : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), type_(type)
@@ -16,6 +17,10 @@ GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedStr
        : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onSelection_(std::move(onSelection)), widgetType_(type)
 {}
 
+GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function<void(GenlistItem *)> onSelection, std::string iconPath, WidgetType type)
+       : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onSelection_(std::move(onSelection)), iconPath_(std::move(iconPath)), widgetType_(type)
+{}
+
 void GenlistItem::setText(const TranslatedString &text)
 {
        text_ = text;
@@ -128,6 +133,9 @@ Evas_Object *GenlistItem::contentRealizator(void *data, Evas_Object *obj, const
        case WidgetType::check:
                return self->realizeCheck(part);
 
+       case WidgetType::icon:
+               return self->realizeIcon(part);
+
        default:
                break;
        }
@@ -176,6 +184,18 @@ Evas_Object *GenlistItem::realizeCheck(const std::string &part)
        return check->getObject();
 }
 
+Evas_Object *GenlistItem::realizeIcon(const std::string &part)
+{
+       if (part != "elm.swallow.icon") return nullptr;
+
+       auto icon = Widget::make<Icon>(genlist_);
+       icon->setColor(15, 41, 73, 255);
+       icon->setImageFile(iconPath_);
+       icon->setAspectHint(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+
+       return icon->getObject();
+}
+
 void GenlistItem::onItemSelection(void *data, Evas_Object *obj, void *event_info)
 {
        SETTING_TRACE_ERROR(".");
index 5190c25..2738c7d 100644 (file)
@@ -21,6 +21,7 @@ public:
        GenlistItem(std::string style, TranslatedString text, TranslatedString desc = {}, Type type = Type::group);
        GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function<void(GenlistItem *)> onSelection, Type type = Type::regular);
        GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function<void(GenlistItem *)> onSelection, WidgetType type);
+       GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function<void(GenlistItem *)> onSelection, std::string iconPath, WidgetType type = WidgetType::icon);
 
        void setText(const TranslatedString &text);
        void setDescription(const TranslatedString &desc);
@@ -40,6 +41,7 @@ private:
        Elm_Genlist_Item_Type getItemType();
        Evas_Object *realizeToggle(const std::string &part);
        Evas_Object *realizeCheck(const std::string &part);
+       Evas_Object *realizeIcon(const std::string &part);
 
        static char *textRealizator(void *data, Evas_Object *obj, const char *part);
        static Evas_Object *contentRealizator(void *data, Evas_Object *obj, const char *part);
@@ -51,6 +53,7 @@ private:
        std::function<void(GenlistItem *)> onSelection_;
        Genlist *genlist_ = nullptr;
        Eina_Bool state_ = EINA_FALSE;
+       std::string iconPath_;
 
        Elm_Object_Item *objItem_ = nullptr;
        Type type_ = Type::regular;
index 9f02098..494f421 100644 (file)
@@ -6,3 +6,8 @@ Icon::Icon(Widget *parent)
        uniqueObj_.reset(elm_icon_add(parent->getObject()));
        show();
 }
+
+void Icon::setImageFile(std::string path)
+{
+       elm_image_file_set(uniqueObj_.get(), path.c_str(), nullptr);
+}
\ No newline at end of file
index 4988e8e..334b559 100644 (file)
@@ -8,6 +8,8 @@ class Icon : public Widget
 public:
        Icon(Widget *parent);
 
+       void setImageFile(std::string path);
+
 };
 
 #endif
index 724dfd7..e419f25 100644 (file)
@@ -58,25 +58,16 @@ void SwitchesPage::updateSwitchesList()
 {
        switches_->clear();
        createSwitchesGroup();
-       createAddButton();
+       switches_->appendItem({"type1", "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES_ADD_SWITCH", {},
+                                                  [this](auto item)
+       {
+               addSwitchPage_ = std::make_unique<AddSwitchPage>(context_);
+               addSwitchPage_->attachCallbackOnSwitchAttach(addSwitchCb, this);
+       }, ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON
+                                                 });
        removeSwitchesPageBtn_->disable(context_->config.configuration_items.size() == 0);
 }
 
-void SwitchesPage::createAddButton()
-{
-       GenGroupItemData *item = createGendialGroupItem(switches_->getObject(), &itc_1text_1icon_3,
-                                                        addSwitchClickedCb, this,
-                                                        SwallowType::ICON_IMAGE, 0,
-                                                        "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES_ADD_SWITCH",
-                                                        {},
-                                                        NULL);
-
-       if (item) {
-               item->l_swallow_path = ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON;
-               item->userdata = context_;
-       }
-}
-
 void SwitchesPage::createSwitchesGroup()
 {
        for (auto &it : context_->config.configuration_items) {
@@ -85,16 +76,6 @@ void SwitchesPage::createSwitchesGroup()
        }
 }
 
-void SwitchesPage::addSwitchClickedCb(void *data, Evas_Object *obj, void *event_info)
-{
-       elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
-       retm_if(data == NULL, "Data argument is NULL");
-       auto self = static_cast<SwitchesPage *>(data);
-
-       self->addSwitchPage_ = std::make_unique<AddSwitchPage>(self->context_);
-       self->addSwitchPage_->attachCallbackOnSwitchAttach(addSwitchCb, self);
-}
-
 void SwitchesPage::switchClickCb(void *data, Evas_Object *obj, void *event_info)
 {
        Elm_Object_Item *item = (Elm_Object_Item *)event_info;
index 2f1394a..87ce7dd 100644 (file)
@@ -48,9 +48,7 @@ public:
 
 private:
        void updateSwitchesList();
-       void createAddButton();
        void createSwitchesGroup();
-       static void addSwitchClickedCb(void *data, Evas_Object *obj, void *event_info);
        static void switchClickCb(void *data, Evas_Object *obj, void *event_info);
        static void switchUpdatedCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name);
        static void switchRemovedCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name);
index 5cc000b..c45f432 100644 (file)
@@ -36,6 +36,11 @@ void Widget::setMaxSizeHint(Evas_Coord v, Evas_Coord h)
        evas_object_size_hint_max_set(uniqueObj_.get(), v, h);
 }
 
+void Widget::setAspectHint(Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h)
+{
+       evas_object_size_hint_aspect_set(uniqueObj_.get(), aspect, w, h);
+}
+
 Rectangle Widget::getGeometry()
 {
        int x, y, w, h;
index a1f1854..682ad84 100644 (file)
@@ -41,6 +41,7 @@ public:
        void setAlignHint(double x, double y);
        void setMinSizeHint(Evas_Coord v, Evas_Coord h);
        void setMaxSizeHint(Evas_Coord v, Evas_Coord h);
+       void setAspectHint(Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h);
        Rectangle getGeometry();
        void setPosition(Point anchor);
        void setEvasSmartCallback(const std::string &eventName, std::function<void()> callback);