diff options
author | Igor Nazarov <i.nazarov@samsung.com> | 2017-04-11 17:42:46 +0300 |
---|---|---|
committer | Igor Nazarov <i.nazarov@samsung.com> | 2017-04-11 18:26:59 +0300 |
commit | 61f0077e2e34394c9c834dd956b18190cec1d8d4 (patch) | |
tree | 2c89803434c8bf21b503e0444161bf7a51a9a0e0 | |
parent | b8591e29a582ccd8cd9b1e1c5a347f3a52708e51 (diff) | |
download | gallery-61f0077e2e34394c9c834dd956b18190cec1d8d4.tar.gz gallery-61f0077e2e34394c9c834dd956b18190cec1d8d4.tar.bz2 gallery-61f0077e2e34394c9c834dd956b18190cec1d8d4.zip |
TizenRefApp-8358 [Gallery] Implement ImageGrid item select logic
- Implemented item select logic in ImageGrid;
- Added Select Mode Startup feature into ImageGrid.
Change-Id: I638a73a2ce7bc1b19f8de5c23ba8e2e4a20f8b38
-rw-r--r-- | edc/image-grid.edc | 7 | ||||
-rw-r--r-- | inc/view/ImageGrid.h | 8 | ||||
-rw-r--r-- | src/view/ImageGrid.cpp | 82 |
3 files changed, 84 insertions, 13 deletions
diff --git a/edc/image-grid.edc b/edc/image-grid.edc index 81ce69d..ad03e26 100644 --- a/edc/image-grid.edc +++ b/edc/image-grid.edc @@ -211,6 +211,13 @@ group { "elm/layout/gallery_image_grid/linear"; target: "image_mask_0"; after: "transition_finished"; } + program { "gallery,force,select,mode"; + signal: "gallery,force,select,mode"; + source: ""; + action: STATE_SET "select_mode"; + target: "spacer"; + target: "image_mask_0"; + } program { "gallery,disable,select,mode"; signal: "gallery,disable,select,mode"; source: ""; diff --git a/inc/view/ImageGrid.h b/inc/view/ImageGrid.h index 712f827..d251b86 100644 --- a/inc/view/ImageGrid.h +++ b/inc/view/ImageGrid.h @@ -42,16 +42,19 @@ namespace gallery { Builder(); Builder &setType(Type value); Builder &setListener(IImageGridListener *value); + Builder &setSelectModeStartup(bool value); ImageGridSRef build(Widget &parent) const; private: Type m_type; IImageGridListener *m_listener; + bool m_selectModeStartup; }; enum { UF_LOSE_IMAGE = 1, UF_LOSE_BG = 2, - UF_BLOCK_CLICKS = 4 + UF_BLOCK_CLICKS = 4, + UF_SELECTED = 8 }; struct ItemParams { @@ -101,7 +104,8 @@ namespace gallery { private: friend class ucl::RefCountObj<ImageGrid>; - ImageGrid(ucl::RefCountObjBase *rc, Type type, Evas_Object *scroller); + ImageGrid(ucl::RefCountObjBase *rc, Evas_Object *scroller, + Type type, bool selectModeStartup); virtual ~ImageGrid(); static const Info &getInfo(Type type); diff --git a/src/view/ImageGrid.cpp b/src/view/ImageGrid.cpp index 0ef6216..da5b427 100644 --- a/src/view/ImageGrid.cpp +++ b/src/view/ImageGrid.cpp @@ -33,6 +33,11 @@ namespace gallery { namespace { namespace impl { // Related to ImageGrid // const TString SLOT_PART_FMT {"swallow.cell_%d"}; + const TString SIGNAL_SELECT_ITEM_FMT {"gallery,select,%d"}; + const TString SIGNAL_UNSELECT_ITEM_FMT {"gallery,unselect,%d"}; + + constexpr EdjeSignal SIGNAL_FORCE_SELECT_MODE + {"gallery,force,select,mode"}; constexpr EdjeSignal SIGNAL_ENABLE_SELECT_MODE {"gallery,enable,select,mode"}; constexpr EdjeSignal SIGNAL_DISABLE_SELECT_MODE @@ -42,7 +47,7 @@ namespace gallery { namespace { namespace impl { // Related to Button // constexpr ElmStyle ITEM_BTN_STYLE {"gallery_image"}; - constexpr EdjePart PART_BTN_BG {"swallow.bg"}; + constexpr EdjePart BTN_PART_BG {"swallow.bg"}; constexpr SmartEvent BTN_CLICKED {"clicked"}; constexpr EdjeSignal BTN_BLOCK_CLICKS {"gallery,block,clicks"}; constexpr EdjeSignal BTN_UNBLOCK_CLICKS {"gallery,unblock,clicks"}; @@ -59,7 +64,8 @@ namespace gallery { ImageGrid::Builder::Builder() : m_type(Type::HCOMB_3X3), - m_listener(nullptr) + m_listener(nullptr), + m_selectModeStartup(false) { } @@ -76,6 +82,13 @@ namespace gallery { return *this; } + ImageGrid::Builder &ImageGrid::Builder::setSelectModeStartup( + const bool value) + { + m_selectModeStartup = value; + return *this; + } + ImageGridSRef ImageGrid::Builder::build(Widget &parent) const { Evas_Object *const scrollerEo = elm_scroller_add(parent); @@ -84,7 +97,8 @@ namespace gallery { return {}; } - auto result = makeShared<ImageGrid>(m_type, scrollerEo); + auto result = makeShared<ImageGrid>(scrollerEo, + m_type, m_selectModeStartup); result->bindToEo(); result->setListener(m_listener); @@ -211,7 +225,8 @@ namespace gallery { m_realizeIndex(-1), m_imageLoadSize(0), m_wasUpdated(false), - m_isClicksBlocked(false) + m_isClicksBlocked(false), + m_isSelected(false) { m_btn.setFocusAlowed(false); m_btn.setStyle(impl::ITEM_BTN_STYLE); @@ -282,6 +297,18 @@ namespace gallery { } } + bool setSelected(const bool selected) + { + if (selected == m_isSelected) { + return false; + } + if (selected && !m_imageGrid.m_isInSelectMode) { + return false; + } + m_isSelected = selected; + return true; + } + bool update(const ItemParams ¶ms) { if (!isRealized()) { @@ -342,7 +369,7 @@ namespace gallery { evas_object_image_filled_add(m_btn.getEvas())); evas_object_image_load_size_set(*m_bgImage, m_imageLoadSize, m_imageLoadSize); - m_btn.setContent(impl::PART_BTN_BG, *m_bgImage); + m_btn.setContent(impl::BTN_PART_BG, *m_bgImage); show(*m_bgImage); } @@ -385,6 +412,7 @@ namespace gallery { int m_imageLoadSize; bool m_wasUpdated; bool m_isClicksBlocked; + bool m_isSelected; }; public: @@ -393,9 +421,12 @@ namespace gallery { m_layout(elm_layout_add(imageGrid.m_box), true), m_isRealized(false) { - if (isValid(m_info.slotThemes[isOdd]) && - !m_layout.setTheme(m_info.slotThemes[isOdd])) { - ELOG("setTheme() failed!"); + if (isValid(m_info.slotThemes[isOdd])) { + if (!m_layout.setTheme(m_info.slotThemes[isOdd])) { + ELOG("setTheme() failed!"); + } else if (imageGrid.m_isInSelectMode) { + m_layout.emitSignal(impl::SIGNAL_FORCE_SELECT_MODE); + } } fill(m_layout); show(m_layout); @@ -455,8 +486,16 @@ namespace gallery { } } + void unselect() + { + for (UInt i = 0; i < m_items.size(); ++i) { + setSelected(i, false); + } + } + bool updateItem(const int itemOffset, const ItemParams ¶ms) { + setSelected(itemOffset, (params.flags & UF_SELECTED)); return m_items[itemOffset]->update(params); } @@ -466,6 +505,18 @@ namespace gallery { } private: + void setSelected(const int itemOffset, const bool selected) + { + if (!m_items[itemOffset]->setSelected(selected)) { + return; + } + const auto aSignal = EdjeSignal(selected ? + impl::SIGNAL_SELECT_ITEM_FMT.format(itemOffset) : + impl::SIGNAL_UNSELECT_ITEM_FMT.format(itemOffset)); + m_layout.emitSignal(aSignal); + } + + private: const Info &m_info; std::vector<SharedRef<Item>> m_items; Layout m_layout; @@ -487,8 +538,8 @@ namespace gallery { // ImageGrid // - ImageGrid::ImageGrid(RefCountObjBase *const rc, const Type type, - Evas_Object *const scroller) : + ImageGrid::ImageGrid(RefCountObjBase *const rc, Evas_Object *const scroller, + const Type type, const bool selectModeStartup) : Widget(rc, scroller, true), m_info(getInfo(type)), @@ -520,7 +571,7 @@ namespace gallery { m_eventsLock(0), m_animator(nullptr), - m_isInSelectMode(false), + m_isInSelectMode(selectModeStartup), m_isRotaryActive(false) { prepare(); @@ -682,6 +733,10 @@ namespace gallery { evas_object_freeze_events_set(*m_scroller, EINA_TRUE); eext_rotary_object_event_activated_set(m_circleScroller, EINA_FALSE); + for (auto &slot: m_slots) { + slot->unselect(); + } + const auto aSignal = (enabled ? impl::SIGNAL_ENABLE_SELECT_MODE : impl::SIGNAL_DISABLE_SELECT_MODE); @@ -789,6 +844,9 @@ namespace gallery { Result ImageGrid::updateItem(const int itemIndex, const ItemParams ¶ms) { + if (m_animator) { + LOG_RETURN(RES_ILLEGAL_STATE, "Transition is in progress."); + } return doWithItem(itemIndex, [¶ms](Slot &slot, const int itemOffset) { @@ -941,6 +999,8 @@ namespace gallery { if (m_slotSize == 0) { UCL_ASSERT(!isOdd, "Must be even!"); + edje_object_message_signal_process( + elm_layout_edje_get(slot->getLayout())); slot->getLayout().calculate(); setSlotSize(slot->getSize()); } |