From 9690aa66af8b156ed856fbdc73e613be05d69abd Mon Sep 17 00:00:00 2001 From: Denis Dolzhenko Date: Wed, 22 Jun 2016 11:44:14 +0300 Subject: [PATCH] Added ability to get thumbnail by custom size Change-Id: I16d9f41ebb940ed3cd593a81b77968805dc7b763 Signed-off-by: Denis Dolzhenko --- src/Common/Utils/inc/ThumbnailMaker.h | 2 +- src/Common/Utils/src/ThumbnailMaker.cpp | 22 ++++++++++++---------- .../ContactList/Controller/src/ContactListItem.cpp | 3 ++- .../ConvList/Controller/src/ConvListItem.cpp | 3 ++- .../Controller/src/BaseThreadListItem.cpp | 3 ++- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Common/Utils/inc/ThumbnailMaker.h b/src/Common/Utils/inc/ThumbnailMaker.h index ed8692e..76169af 100644 --- a/src/Common/Utils/inc/ThumbnailMaker.h +++ b/src/Common/Utils/inc/ThumbnailMaker.h @@ -50,7 +50,7 @@ namespace Msg ThumbId getThumbId(const MsgAddress &address); ThumbId getThumbId(const std::string &address); ThumbId getThumbId(DefaultThumbs thumb); - Evas_Object *getThumbById(Evas_Object *parent, ThumbId id); + Evas_Object *getThumbById(Evas_Object *parent, ThumbId id, int thumbSize); private: typedef std::unordered_map ContactsMap; diff --git a/src/Common/Utils/src/ThumbnailMaker.cpp b/src/Common/Utils/src/ThumbnailMaker.cpp index 3c1bfda..a42e2f2 100644 --- a/src/Common/Utils/src/ThumbnailMaker.cpp +++ b/src/Common/Utils/src/ThumbnailMaker.cpp @@ -24,13 +24,14 @@ using namespace Msg; -const int defaultThumbSize = 80; const int defaultCache = 512; +#define DEFAULT_THUMB_SIZE ELM_SCALE_SIZE(80) #define COLOR_BLUE 61, 185, 204, 255 #define RAND (rand() % 220) #define COLOR_RAND RAND, RAND, RAND, 255 #define MSG_THUMB_STYLE_LIST "list_ic_user_thumb_masking" + ThumbnailMaker::ThumbnailMaker(App &app) : m_App(app) , m_ContactsMap() @@ -108,7 +109,7 @@ ThumbnailMaker::ThumbId ThumbnailMaker::getThumbId(DefaultThumbs thumb) } } -Evas_Object *ThumbnailMaker::getThumbById(Evas_Object *parent, ThumbId id) +Evas_Object *ThumbnailMaker::getThumbById(Evas_Object *parent, ThumbId id, int thumbSize) { auto it = m_OriginsMap.find(id); if(it == m_OriginsMap.end()) @@ -120,8 +121,9 @@ Evas_Object *ThumbnailMaker::getThumbById(Evas_Object *parent, ThumbId id) Evas_Object *origin = it->second; Evas_Object *ic = evas_object_image_filled_add(evas_object_evas_get(parent)); evas_object_image_source_set(ic, origin); - evas_object_size_hint_min_set(ic, ELM_SCALE_SIZE(defaultThumbSize), ELM_SCALE_SIZE(defaultThumbSize)); - evas_object_size_hint_max_set(ic, ELM_SCALE_SIZE(defaultThumbSize), ELM_SCALE_SIZE(defaultThumbSize)); + int scaledThumbSize = ELM_SCALE_SIZE(thumbSize); + evas_object_size_hint_min_set(ic, scaledThumbSize, scaledThumbSize); + evas_object_size_hint_max_set(ic, scaledThumbSize, scaledThumbSize); View::expand(ic); evas_object_show(ic); return ic; @@ -135,8 +137,8 @@ Evas_Object *ThumbnailMaker::makeOriginThumb(Evas_Object *parent, const std::str Evas_Object *img = makeFace(ic, path); elm_object_part_content_set(ic, "content", img); - evas_object_resize(ic, ELM_SCALE_SIZE(defaultThumbSize), ELM_SCALE_SIZE(defaultThumbSize)); - evas_object_move(ic, -ELM_SCALE_SIZE(defaultThumbSize), -ELM_SCALE_SIZE(defaultThumbSize)); + evas_object_resize(ic, DEFAULT_THUMB_SIZE, DEFAULT_THUMB_SIZE); + evas_object_move(ic, -DEFAULT_THUMB_SIZE, -DEFAULT_THUMB_SIZE); evas_object_show(ic); return ic; } @@ -145,8 +147,8 @@ Evas_Object *ThumbnailMaker::makeDefaultOriginThumb(Evas_Object *parent, const s { Evas_Object *img = makeFace(parent, path); evas_object_color_set(img, COLOR_BLUE); - evas_object_resize(img, ELM_SCALE_SIZE(defaultThumbSize), ELM_SCALE_SIZE(defaultThumbSize)); - evas_object_move(img, -ELM_SCALE_SIZE(defaultThumbSize), -ELM_SCALE_SIZE(defaultThumbSize)); + evas_object_resize(img, DEFAULT_THUMB_SIZE, DEFAULT_THUMB_SIZE); + evas_object_move(img, -DEFAULT_THUMB_SIZE, -DEFAULT_THUMB_SIZE); evas_object_show(img); return img; } @@ -155,8 +157,8 @@ Evas_Object *ThumbnailMaker::makeFace(Evas_Object *parent, const std::string &pa { Evas_Object *img = elm_image_add(parent); elm_image_file_set(img, path.c_str(), nullptr); - evas_object_size_hint_min_set(img, ELM_SCALE_SIZE(defaultThumbSize), ELM_SCALE_SIZE(defaultThumbSize)); - evas_object_size_hint_max_set(img, ELM_SCALE_SIZE(defaultThumbSize), ELM_SCALE_SIZE(defaultThumbSize)); + evas_object_size_hint_min_set(img, DEFAULT_THUMB_SIZE, DEFAULT_THUMB_SIZE); + evas_object_size_hint_max_set(img, DEFAULT_THUMB_SIZE, DEFAULT_THUMB_SIZE); elm_image_aspect_fixed_set(img, EINA_TRUE); elm_image_fill_outside_set(img, EINA_TRUE); return img; diff --git a/src/Conversation/ContactList/Controller/src/ContactListItem.cpp b/src/Conversation/ContactList/Controller/src/ContactListItem.cpp index b7401f9..567cbfb 100644 --- a/src/Conversation/ContactList/Controller/src/ContactListItem.cpp +++ b/src/Conversation/ContactList/Controller/src/ContactListItem.cpp @@ -72,5 +72,6 @@ std::string ContactListItem::getMainText() const Evas_Object *ContactListItem::getThumbnail() const { - return m_App.getThumbnailMaker().getThumbById(*getOwner(), m_ThumbId); + static const int thumbSize = 80; + return m_App.getThumbnailMaker().getThumbById(*getOwner(), m_ThumbId, thumbSize); } diff --git a/src/Conversation/ConvList/Controller/src/ConvListItem.cpp b/src/Conversation/ConvList/Controller/src/ConvListItem.cpp index de38e32..6f3245a 100644 --- a/src/Conversation/ConvList/Controller/src/ConvListItem.cpp +++ b/src/Conversation/ConvList/Controller/src/ConvListItem.cpp @@ -227,7 +227,8 @@ Evas_Object *ConvListItem::getBubbleContent() Evas_Object *ConvListItem::getThumbnail() { - return m_App.getThumbnailMaker().getThumbById(*getOwner(), m_ThumbId); + static const int thumbSize = 80; + return m_App.getThumbnailMaker().getThumbById(*getOwner(), m_ThumbId, thumbSize); } Evas_Object *ConvListItem::getProgress() diff --git a/src/MsgThread/Controller/src/BaseThreadListItem.cpp b/src/MsgThread/Controller/src/BaseThreadListItem.cpp index ea3a624..1de36f9 100644 --- a/src/MsgThread/Controller/src/BaseThreadListItem.cpp +++ b/src/MsgThread/Controller/src/BaseThreadListItem.cpp @@ -129,7 +129,8 @@ std::string BaseThreadListItem::getTime() Evas_Object *BaseThreadListItem::getThumbnail() { - return m_App.getThumbnailMaker().getThumbById(*getOwner(), m_ThumbId); + static const int thumbSize = 98; + return m_App.getThumbnailMaker().getThumbById(*getOwner(), m_ThumbId, thumbSize); } time_t BaseThreadListItem::getRawTime() const -- 2.7.4