2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file ClTaskItem.cpp
19 * @brief This is the implementation file for the TaskItem class.
22 #include "ClTaskItem.h"
23 #include "ClResourceManager.h"
25 using namespace Tizen::Base;
26 using namespace Tizen::Graphics;
27 using namespace Tizen::Locales;
28 using namespace Tizen::Ui;
29 using namespace Tizen::Ui::Controls;
31 enum TaskItemElementId
33 ID_TASK_ITEM_ELEMENT_COLOR_BAR,
34 ID_TASK_ITEM_ELEMENT_TITLE,
35 ID_TASK_ITEM_ELEMENT_LOCATION,
36 ID_TASK_ITEM_ELEMENT_DUE_DATE,
37 ID_TASK_ITEM_ELEMENT_PRIORITY,
38 ID_TASK_ITEM_ELEMENT_REMINDER,
39 ID_TASK_ITEM_ELEMENT_FACEBOOK
42 static const int H_ITEM = 140;
43 static const unsigned int COLOR_ITEM_BACKGROUND = Color32<248, 246, 239>::Value;
44 static const int X_ITEM_MAIN_CONTENT = 26;
45 static const int Y_ITEM_MAIN_CONTENT = 0;
46 static const int W_ITEM_MAIN_CONTENT_MARGIN = 16;
47 static const int H_ITEM_MAIN_CONTENT = 54;
48 static const int FONT_SIZE_ITEM_MAIN_CONTENT = 44;
49 static const unsigned int COLOR_ITEM_MAIN_CONTENT = Color32<0, 0, 0>::Value;
50 static const unsigned int COLOR_ITEM_MAIN_CONTENT_HIGH_PRIORITY = Color32<194, 71, 71>::Value;
51 static const unsigned int COLOR_ITEM_MAIN_CONTENT_FOCUS = Color32<255, 255, 255>::Value;
52 static const int X_ITEM_SUB_CONTENT = 26;
53 static const int Y_ITEM_SUB_CONTENT = 85;
54 static const int W_ITEM_SUB_CONTENT_MARGIN = 26;
55 static const int H_ITEM_SUB_CONTENT = 38;
56 static const int FONT_SIZE_ITEM_SUB_CONTENT = 32;
57 static const unsigned int COLOR_ITEM_SUB_CONTENT = Color32<128, 128, 128>::Value;
58 static const unsigned int COLOR_ITEM_SUB_CONTENT_FOCUS = Color32<255, 255, 255>::Value;
59 static const int Y_EVENT_COLOR_BAR = 4;
60 static const int W_EVENT_COLOR_BAR = 8;
61 static const int H_EVENT_COLOR_BAR = 132;
62 static const int W_ICON = 45;
63 static const int H_ICON = 45;
64 static const int W_RANGE_TO_LOCATION_MARGIN = 26;
65 static const int LIST_ANNEX_MARGIN = 30;
66 static const byte COLOR_COMPLETE_TASK_ALPHA = 77; // 30% alpha
67 static const int W_MIN_CHAR = 20;
68 static const int H_SPARE = 14;
69 static const int H_APPROX = 17;
72 class TaskTitleElement
73 : public virtual ICustomElement
76 TaskTitleElement(const String& title, TaskPriority priority, float fontsize, bool isCompleted = false);
77 virtual ~TaskTitleElement(void);
79 virtual bool OnDraw(Canvas& canvas, const Rectangle& rect, ListItemDrawingStatus status);
82 const String& __title;
83 TaskPriority __priority;
88 TaskTitleElement::TaskTitleElement(const String& title, TaskPriority priority, float fontsize, bool isCompleted)
90 , __priority(priority)
91 , __isCompleted(isCompleted)
92 , __fontSize(fontsize)
96 TaskTitleElement::~TaskTitleElement(void)
101 TaskTitleElement::OnDraw(Canvas& canvas, const Rectangle& rect, ListItemDrawingStatus status)
104 text.Construct(Dimension(rect.width, rect.height));
105 text.SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
106 text.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
107 text.SetTextAbbreviationEnabled(true);
110 if (status == LIST_ITEM_DRAWING_STATUS_PRESSED || status == LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED)
112 titleColor = Color(COLOR_ITEM_MAIN_CONTENT_FOCUS);
114 else if (__priority == TASK_PRIORITY_HIGH)
116 titleColor = Color(COLOR_ITEM_MAIN_CONTENT_HIGH_PRIORITY);
120 titleColor = Color(COLOR_ITEM_MAIN_CONTENT);
124 font.Construct(FONT_STYLE_PLAIN, __fontSize);
126 if (__isCompleted == true)
128 font.SetStrikeOut(true);
129 titleColor.SetAlpha(COLOR_COMPLETE_TASK_ALPHA);
132 TextElement* pTextElement = new (std::nothrow) TextElement();
133 pTextElement->Construct(__title);
134 pTextElement->SetFont(font);
135 pTextElement->SetTextColor(Color(titleColor));
136 text.Add(*pTextElement);
138 canvas.DrawText(Point(rect.x, rect.y), text);
139 text.RemoveAll(true);
144 TaskItem::TaskItem(void)
147 , __pTitleElement(null)
148 , __priority(TASK_PRIORITY_LOW)
149 , __hasReminder(false)
150 , __isCanceled(false)
151 , __isCompleted(false)
152 , __isFacebook(false)
156 TaskItem::~TaskItem(void)
158 delete __pTitleElement;
162 TaskItem::GetCalendarColor(void) const
164 return __calendarColor;
168 TaskItem::GetDueDateText(void) const
174 TaskItem::GetLocation(void) const
180 TaskItem::GetMainContentHeight() const
182 return (__itemHeight - (H_APPROX*2) - H_SPARE);
186 TaskItem::GetPriority(void) const
192 TaskItem::GetSubItemY() const
194 return (__itemHeight - H_APPROX - H_ITEM_SUB_CONTENT );
198 TaskItem::GetTitle(void) const
204 TaskItem::HasReminder(void) const
206 return __hasReminder;
210 TaskItem::Initialize(TaskItemStyle style, int width, float height)
212 if (style == TASK_ITEM_STYLE_NORMAL)
214 Construct(Dimension(width, height), LIST_ANNEX_STYLE_NORMAL);
216 __itemHeight = height;
220 Construct(Dimension(width, height), LIST_ANNEX_STYLE_MARK);
221 __width = width - GetAnnexWidth(LIST_ANNEX_STYLE_MARK) - LIST_ANNEX_MARGIN;
222 __itemHeight = height;
228 TaskItem::IsCanceledTask(void) const
234 TaskItem::IsCompletedTask(void) const
236 return __isCompleted;
240 TaskItem::IsFacebookTask(void) const
246 TaskItem::SetCalendarColor(const Color& calendarColor)
248 __calendarColor = calendarColor;
252 TaskItem::SetCanceled(bool isCanceled)
254 __isCanceled = isCanceled;
258 TaskItem::SetCompleted(bool isCompleted)
260 __isCompleted = isCompleted;
264 TaskItem::SetDueDate(const DateTime& dueDate, DateTimeFormatter* pTimeFormatter)
266 bool deleteRequired = false;
267 if (pTimeFormatter == null)
269 pTimeFormatter = ResourceManager::CreateDateTimeFormatterN(DATE_TIME_STYLE_SHORT);
270 deleteRequired = true;
274 pTimeFormatter->Format(dueDate, dueDateText);
275 if (deleteRequired == true)
277 delete pTimeFormatter;
279 SetDueDateText(dueDateText);
283 TaskItem::SetDueDateText(const String& range)
289 TaskItem::SetFacebookEvent(bool isFacebookEvent)
291 __isFacebook = isFacebookEvent;
295 TaskItem::SetFontSize(const float& size)
301 TaskItem::SetLocation(const String& location)
303 __location = location;
307 TaskItem::SetPriority(TaskPriority priority)
309 __priority = priority;
313 TaskItem::SetReminder(bool hasReminder)
315 __hasReminder = hasReminder;
319 TaskItem::SetTitle(const String& title)
325 TaskItem::UpdateElements(void)
329 Bitmap* pBitmap = new (std::nothrow) Bitmap();
330 pBitmap->Construct(Dimension(W_EVENT_COLOR_BAR, __itemHeight), BITMAP_PIXEL_FORMAT_ARGB8888);
332 BufferInfo bufferinfo;
333 pBitmap->Lock(bufferinfo);
336 canvas.Construct(bufferinfo);
340 AddElement(Rectangle(0, Y_EVENT_COLOR_BAR, W_EVENT_COLOR_BAR, __itemHeight), ID_TASK_ITEM_ELEMENT_COLOR_BAR, *pBitmap);
343 int titleWidth = __width - X_ITEM_MAIN_CONTENT;
344 if (__hasReminder == true)
346 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LIST_ICON_REMINDER);
349 AddElement(Rectangle(titleWidth - W_ICON, Y_ITEM_MAIN_CONTENT + ((GetMainContentHeight() - H_ICON) / 2), W_ICON, H_ICON),
350 ID_TASK_ITEM_ELEMENT_REMINDER, *pBitmap);
351 titleWidth -= W_ICON;
356 if (__priority == TASK_PRIORITY_LOW)
358 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LIST_ICON_PRIORITY_LOW);
361 AddElement(Rectangle(titleWidth - W_ICON, Y_ITEM_MAIN_CONTENT + ((GetMainContentHeight() - H_ICON) / 2), W_ICON, H_ICON),
362 ID_TASK_ITEM_ELEMENT_PRIORITY, *pBitmap);
363 titleWidth -= W_ICON;
367 else if (__priority == TASK_PRIORITY_HIGH)
369 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LIST_ICON_PRIORITY);
372 AddElement(Rectangle(titleWidth - W_ICON, Y_ITEM_MAIN_CONTENT + ((GetMainContentHeight() - H_ICON) / 2), W_ICON, H_ICON),
373 ID_TASK_ITEM_ELEMENT_PRIORITY, *pBitmap);
374 titleWidth -= W_ICON;
379 if (__isFacebook == true)
381 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_LIST_ICON_FACEBOOK);
384 AddElement(Rectangle(titleWidth - W_ICON, Y_ITEM_MAIN_CONTENT + ((GetMainContentHeight() - H_ICON) / 2), W_ICON, H_ICON),
385 ID_TASK_ITEM_ELEMENT_FACEBOOK, *pBitmap);
386 titleWidth -= W_ICON;
391 if (__title.IsEmpty() == false)
393 delete __pTitleElement;
394 __pTitleElement = new (std::nothrow) TaskTitleElement(__title, __priority, __fontSize, __isCompleted);
396 if (titleWidth < __width - X_ITEM_MAIN_CONTENT)
398 titleWidth -= W_ITEM_MAIN_CONTENT_MARGIN;
401 AddElement(Rectangle(X_ITEM_MAIN_CONTENT, Y_ITEM_MAIN_CONTENT, titleWidth - X_ITEM_MAIN_CONTENT, GetMainContentHeight()),
402 ID_TASK_ITEM_ELEMENT_TITLE, *__pTitleElement);
405 int dueDateWidth = 0;
406 if (__dueDate.IsEmpty() == false)
410 font.Construct(FONT_STYLE_PLAIN, FONT_SIZE_ITEM_SUB_CONTENT);
411 font.GetTextExtent(__dueDate, __dueDate.GetLength(), extent);
412 dueDateWidth = extent.width;
414 AddElement(Rectangle(X_ITEM_SUB_CONTENT, GetSubItemY(), dueDateWidth, H_ITEM_SUB_CONTENT),
415 ID_TASK_ITEM_ELEMENT_DUE_DATE, __dueDate, FONT_SIZE_ITEM_SUB_CONTENT,
416 Color(COLOR_ITEM_SUB_CONTENT), Color(COLOR_ITEM_SUB_CONTENT_FOCUS), Color(COLOR_ITEM_SUB_CONTENT_FOCUS));
419 int locationWidth = __width - X_ITEM_SUB_CONTENT - W_ITEM_SUB_CONTENT_MARGIN - W_RANGE_TO_LOCATION_MARGIN - dueDateWidth;
420 if (__location.IsEmpty() == false)
424 font.Construct(FONT_STYLE_PLAIN, FONT_SIZE_ITEM_SUB_CONTENT);
425 font.GetTextExtent(__location, __location.GetLength(), extent);
426 if (locationWidth > extent.width)
428 locationWidth = extent.width;
431 AddElement(Rectangle(__width - locationWidth - W_ITEM_SUB_CONTENT_MARGIN, GetSubItemY(), locationWidth, H_ITEM_SUB_CONTENT),
432 ID_TASK_ITEM_ELEMENT_LOCATION, __location, FONT_SIZE_ITEM_SUB_CONTENT,
433 Color(COLOR_ITEM_SUB_CONTENT), Color(COLOR_ITEM_SUB_CONTENT_FOCUS), Color(COLOR_ITEM_SUB_CONTENT_FOCUS));
434 SetElementTextHorizontalAlignment(ID_TASK_ITEM_ELEMENT_LOCATION, ALIGNMENT_RIGHT);