TizenRefApp-8252 [Gallery] Integrate custom image button to thumbnail view 34/121334/4
authorIgor Nazarov <i.nazarov@samsung.com>
Mon, 27 Mar 2017 16:30:28 +0000 (19:30 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Tue, 28 Mar 2017 11:15:16 +0000 (14:15 +0300)
- Button with "gallery_image" style inetgrated into ImageGrid;
- Added onItemClicked() method into IImageGridListener interface;
- Added dummy onItemClicked() handler into ThumbnailPage class.

Change-Id: Idb05e84b7a50705ad27167f84cd95b05f5de92a9

inc/presentation/IImageGridListener.h
inc/presentation/ImageGrid.h
inc/presentation/ThumbnailPage.h
src/presentation/ImageGrid.cpp
src/presentation/ThumbnailPage.cpp
ucl/inc/ucl/gui/ElmWidget.h
ucl/inc/ucl/gui/ElmWidget.hpp

index 96291a1e553c2f3eae6202526fdf1f982fc8b34a..abc1abf806e8696bdb748088cbafd8985ccc3bd7 100644 (file)
@@ -25,6 +25,7 @@ namespace gallery {
        public:
                virtual void onItemRealized(int itemIndex) = 0;
                virtual void onItemUnrealized(int itemIndex) = 0;
+               virtual void onItemClicked(int itemIndex) = 0;
        };
 }
 
index 88a44144a780f600031afb5737557831347e705b..11f84578293865e905c0c4e41e43a598ece5f6bb 100644 (file)
@@ -87,6 +87,8 @@ namespace gallery {
                void addUnrealizeLock();
                void removeUnrealizeLock();
 
+               void handleItemClick(int itemIndex) const;
+
                // Initialization
                void prepare();
                void createCircleScroller();
@@ -173,6 +175,7 @@ namespace gallery {
                int m_scrollOffset;
 
                int m_unrealizeLock;
+               int m_eventsLock;
        };
 }
 
index 8f39816f775d72a544ea4a57f2e816e990ba4114..c866439ceca6c363ffe84af865228459213545e7 100644 (file)
@@ -62,6 +62,7 @@ namespace gallery {
 
                virtual void onItemRealized(int itemIndex) final override;
                virtual void onItemUnrealized(int itemIndex) final override;
+               virtual void onItemClicked(int itemIndex) final override;
 
        private:
                class RealizedItem;
index 70a41c408628d4f616cf743c78f0cf534e387054..18b7c0ca65f0ab5945fdc727c82fef09116a56aa 100644 (file)
@@ -29,7 +29,11 @@ namespace gallery { namespace { namespace impl {
 
        using namespace ucl;
 
-       const TString SLOT_PART_FMT = {"swallow.cell_%d"};
+       const TString SLOT_PART_FMT {"swallow.cell_%d"};
+
+       constexpr ElmStyle ITEM_BTN_STYLE {"gallery_image"};
+
+       constexpr SmartEvent BTN_CLICKED {"clicked"};
 }}}
 
 namespace gallery {
@@ -137,20 +141,31 @@ namespace gallery {
 
        class ImageGrid::Slot {
        private:
-               class Item {
+               class Item : public RefCountAware {
                public:
-                       Item(const ImageGrid &imageGrid, Widget &parent) :
+                       friend class RefCountObj<Item>;
+                       Item(RefCountObjBase &rc,
+                                       const ImageGrid &imageGrid, Widget &parent) :
+                               RefCountAware(&rc),
                                m_imageGrid(imageGrid),
-                               m_image(evas_object_image_filled_add(parent.getEvas())),
+                               m_btn(elm_button_add(parent)),
+                               m_image(evas_object_image_filled_add(m_btn.getEvas())),
                                m_realizeIndex(-1),
                                m_wasUpdated(false)
                        {
+                               m_btn.setFocusAlowed(false);
+                               m_btn.setStyle(impl::ITEM_BTN_STYLE);
+                               m_btn.setContent(m_image);
+                               show(m_btn);
                                show(m_image);
+
+                               m_btn.addEventHandler(impl::BTN_CLICKED, WEAK_DELEGATE(
+                                               Item::onClicked, asWeak(*this)));
                        }
 
                        Widget &getWidget()
                        {
-                               return m_image;
+                               return m_btn;
                        }
 
                        void setImageLoadSize(const int value)
@@ -180,7 +195,7 @@ namespace gallery {
                                }
 
                                if (!m_wasUpdated) {
-                                       makeTransparent(m_image);
+                                       makeTransparent(m_btn);
                                }
                        }
 
@@ -207,7 +222,7 @@ namespace gallery {
                                m_wasUpdated = true;
 
                                if (isEmpty(params.imagePath)) {
-                                       makeTransparent(m_image);
+                                       makeTransparent(m_btn);
                                        return true;
                                }
 
@@ -218,13 +233,22 @@ namespace gallery {
                                evas_object_image_size_get(m_image, &w, &h);
                                m_image.setARHint(WidgetARHint::NEITHER, w, h);
 
-                               makeWhite(m_image);
+                               makeWhite(m_btn);
 
                                return true;
                        }
 
+               private:
+                       void onClicked(Widget &wifget, void *eventInfo)
+                       {
+                               if (isRealized()) {
+                                       m_imageGrid.handleItemClick(m_realizeIndex);
+                               }
+                       }
+
                private:
                        const ImageGrid &m_imageGrid;
+                       StyledWidget m_btn;
                        Widget m_image;
                        int m_realizeIndex;
                        bool m_wasUpdated;
@@ -244,7 +268,7 @@ namespace gallery {
 
                        const int length = m_info.slotLens[isOdd];
                        for (int i = 0; i < length; ++i) {
-                               m_items.emplace_back(new Item(imageGrid, m_layout));
+                               m_items.emplace_back(makeShared<Item>(imageGrid, m_layout));
 
                                m_layout.setContent(
                                                EdjePart(impl::SLOT_PART_FMT.format(i)),
@@ -310,7 +334,7 @@ namespace gallery {
 
        private:
                const Info &m_info;
-               std::vector<std::unique_ptr<Item>> m_items;
+               std::vector<SharedRef<Item>> m_items;
                Layout m_layout;
                bool m_isRealized;
        };
@@ -359,15 +383,20 @@ namespace gallery {
                m_scrollerSize(1), // Must not be 0
                m_scrollOffset(0),
 
-               m_unrealizeLock(0)
+               m_unrealizeLock(0),
+               m_eventsLock(0)
        {
                prepare();
 
+               ++m_eventsLock;
+
                updateSlotCount();
 
                updatePadSizes();
                updateScrollBias();
                updateRectMins();
+
+               --m_eventsLock;
        }
 
        const ImageGrid::Info &ImageGrid::getInfo(const Type type)
@@ -413,13 +442,13 @@ namespace gallery {
                createCircleScroller();
 
                m_scroller->addEventHandler(WidgetEvent::RESIZE,
-                               WEAK_DELEGATE(ImageGrid::onScrollerResize, asWeak(this)));
+                               WEAK_DELEGATE(ImageGrid::onScrollerResize, asWeak(*this)));
 
                m_scroller->addEventHandler(WidgetEvent::MOVE,
-                               WEAK_DELEGATE(ImageGrid::onScrollerMove, asWeak(this)));
+                               WEAK_DELEGATE(ImageGrid::onScrollerMove, asWeak(*this)));
 
                m_box.addEventHandler(WidgetEvent::MOVE,
-                               WEAK_DELEGATE(ImageGrid::onBoxMove, asWeak(this)));
+                               WEAK_DELEGATE(ImageGrid::onBoxMove, asWeak(*this)));
        }
 
        void ImageGrid::createCircleScroller()
@@ -450,6 +479,8 @@ namespace gallery {
                        return;
                }
 
+               ++m_eventsLock;
+
                unrealizeSlots(0, m_slotCount);
 
                m_itemCount = count;
@@ -463,6 +494,8 @@ namespace gallery {
 
                realizeSlots();
                updateRectMins();
+
+               --m_eventsLock;
        }
 
        void ImageGrid::update()
@@ -535,6 +568,13 @@ namespace gallery {
                }
        }
 
+       void ImageGrid::handleItemClick(const int itemIndex) const
+       {
+               if (m_listener) {
+                       m_listener->onItemClicked(itemIndex);
+               }
+       }
+
        bool ImageGrid::updateSlotCount()
        {
                const int newSlotCount = calcSlotCount();
@@ -852,14 +892,28 @@ namespace gallery {
 
        void ImageGrid::handleScrolling()
        {
+               if (m_eventsLock > 0) {
+                       WLOG("Event handling was blocked!");
+                       return;
+               }
+               ++m_eventsLock;
+
                if (updateScrollOffset() && updateBeginSlotIndex()) {
                        realizeSlots();
                        updateRectMins();
                }
+
+               --m_eventsLock;
        }
 
        void ImageGrid::handleResize()
        {
+               if (m_eventsLock > 0) {
+                       WLOG("Event handling was blocked!");
+                       return;
+               }
+               ++m_eventsLock;
+
                if (updateScrollerSize()) {
                        bool needRealize = false;
 
@@ -881,6 +935,8 @@ namespace gallery {
                        }
                        updateRectMins();
                }
+
+               --m_eventsLock;
        }
 
        void ImageGrid::onScrollerResize(Widget &sender, void *eventInfo)
index 162cc60db2707199edfba9df5ce71ac81afca24d..ab8b657d96caba5013fa27defa0f17545029b3ab 100644 (file)
@@ -199,4 +199,9 @@ namespace gallery {
                        WLOG("Item is not found in realized list!");
                }
        }
+
+       void ThumbnailPage::onItemClicked(const int itemIndex)
+       {
+               ILOG("TODO Not implemented. Item: %d;", itemIndex);
+       }
 }
index 91825d6cf579be4c268369e84e0ea8ff97c3ef2d..9c03011a06bfa723b8b636d240000bbdfff07115 100644 (file)
@@ -33,6 +33,9 @@ namespace ucl {
                void setEnabled(bool value);
                bool isEnabled() const;
 
+               void setFocusAlowed(bool value);
+               bool isFocusAlowed() const;
+
                void setTheme(Elm_Theme *th);
                Elm_Theme *getTheme();
 
index 482367379f37f1f259f63e8aa0ddd0a84bed7041..8d0e1abb4161d06f554926dcaa762e937045a4b1 100644 (file)
@@ -26,6 +26,16 @@ namespace ucl {
                return !elm_object_disabled_get(getEo());
        }
 
+       inline void ElmWidget::setFocusAlowed(const bool value)
+       {
+               elm_object_focus_allow_set(getEo(), toEina(value));
+       }
+
+       inline bool ElmWidget::isFocusAlowed() const
+       {
+               return elm_object_focus_allow_get(getEo());
+       }
+
        inline void ElmWidget::setTheme(Elm_Theme *th)
        {
                elm_object_theme_set(getEo(), th);