phonebookui/pbkcommonui/src/cnthistoryviewitemwidget.cpp
changeset 31 2a11b5b00470
parent 27 de1630741fbe
child 33 e1c7b0febd15
child 37 fd64c38c277d
equal deleted inserted replaced
27:de1630741fbe 31:2a11b5b00470
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cnthistoryviewitemwidget.h"
       
    19 
       
    20 #include <hbiconitem.h>
       
    21 #include <hbtextitem.h>
       
    22 #include <hbframedrawer.h>
       
    23 #include <hbframeitem.h>
       
    24 
       
    25 #define INCOMING_EVENT_FRAME "qtg_fr_convlist_received_normal"
       
    26 #define OUTGOING_EVENT_FRAME "qtg_fr_convlist_sent_normal"
       
    27 #define NEW_EVENT_FRAME "qtg_fr_list_new_item"
       
    28 
       
    29 CntHistoryViewItemWidget::CntHistoryViewItemWidget(QGraphicsItem *parent) :
       
    30     HbWidget(parent),
       
    31     mIconLabel(NULL),
       
    32     mTitleLabel(NULL),
       
    33     mBodyTextLabel(NULL),
       
    34     mTimeStampLabel(NULL),
       
    35     mFrameLabel(NULL),
       
    36     mNewItemLabel(NULL),
       
    37     mIncoming(false),
       
    38     mNewMessage(false)
       
    39 {
       
    40 }
       
    41 
       
    42 CntHistoryViewItemWidget::~CntHistoryViewItemWidget()
       
    43 {
       
    44 }
       
    45 
       
    46 void CntHistoryViewItemWidget::createPrimitives()
       
    47 {
       
    48     //create frame first so it's painted below text labels
       
    49     if (!mFrameLabel) {
       
    50         HbFrameDrawer* frameDrawer = NULL;
       
    51         if (mIncoming) {
       
    52             frameDrawer = new HbFrameDrawer(INCOMING_EVENT_FRAME, HbFrameDrawer::NinePieces);
       
    53         } else {
       
    54             frameDrawer = new HbFrameDrawer(OUTGOING_EVENT_FRAME, HbFrameDrawer::NinePieces);
       
    55         }
       
    56         mFrameLabel = new HbFrameItem(frameDrawer, this);
       
    57         style()->setItemName(mFrameLabel, "frame");
       
    58     }
       
    59     
       
    60     if (mNewMessage && !mNewItemLabel) {
       
    61         HbFrameDrawer* frameDrawer = new HbFrameDrawer(NEW_EVENT_FRAME, HbFrameDrawer::ThreePiecesVertical);
       
    62         mNewItemLabel = new HbFrameItem(frameDrawer, this);
       
    63         style()->setItemName(mNewItemLabel, "newItem");
       
    64     }
       
    65 
       
    66     //create icon
       
    67     if (!mIcon.isNull()) {
       
    68         if (!mIconLabel) {
       
    69             mIconLabel = new HbIconItem(this);
       
    70             mIconLabel->setIcon(mIcon);
       
    71             style()->setItemName(mIconLabel, "icon");
       
    72         }
       
    73     } else {
       
    74         if (mIconLabel) {
       
    75             delete mIconLabel;
       
    76         }
       
    77         mIconLabel = NULL;
       
    78     }
       
    79 
       
    80     //create title
       
    81     if (!mTitle.isNull()) {
       
    82         if (!mTitleLabel) {
       
    83             mTitleLabel = new HbTextItem(this);
       
    84             mTitleLabel->setText(mTitle);
       
    85             mTitleLabel->setTextWrapping(Hb::TextWordWrap);
       
    86             style()->setItemName(mTitleLabel, "title");
       
    87         }
       
    88     } else {
       
    89         if (mTitleLabel) {
       
    90             delete mTitleLabel;
       
    91         }
       
    92         mTitleLabel = NULL;
       
    93     }
       
    94 
       
    95     //create body text
       
    96     if (!mBodyText.isNull()) {
       
    97         if (!mBodyTextLabel) {
       
    98             mBodyTextLabel = new HbTextItem(this);
       
    99             mBodyTextLabel->setText(mBodyText);
       
   100             style()->setItemName(mBodyTextLabel, "bodyText");
       
   101         }
       
   102     } else {
       
   103         if (mBodyTextLabel) {
       
   104             delete mBodyTextLabel;
       
   105         }
       
   106         mBodyTextLabel = NULL;
       
   107     }
       
   108 
       
   109     //create timestamp
       
   110     if (!mTimeStamp.isNull()) {
       
   111         if (!mTimeStampLabel) {
       
   112             mTimeStampLabel = new HbTextItem(this);
       
   113             mTimeStampLabel->setText(mTimeStamp);
       
   114             style()->setItemName(mTimeStampLabel, "timeStamp");
       
   115         }
       
   116     } else {
       
   117         if (mTimeStampLabel) {
       
   118             delete mTimeStampLabel;
       
   119         }
       
   120         mTimeStampLabel = NULL;
       
   121     }
       
   122 }
       
   123 
       
   124 void CntHistoryViewItemWidget::recreatePrimitives()
       
   125 {
       
   126     HbWidget::recreatePrimitives();
       
   127 
       
   128     delete mIconLabel;
       
   129     mIconLabel = NULL;
       
   130 
       
   131     delete mTitleLabel;
       
   132     mTitleLabel = NULL;
       
   133 
       
   134     delete mBodyTextLabel;
       
   135     mBodyTextLabel = NULL;
       
   136 
       
   137     delete mTimeStampLabel;
       
   138     mTimeStampLabel = NULL;
       
   139     
       
   140     createPrimitives();
       
   141 }
       
   142 
       
   143 
       
   144 void CntHistoryViewItemWidget::updatePrimitives()
       
   145 {
       
   146     HbWidget::updatePrimitives();
       
   147 }
       
   148 
       
   149 void CntHistoryViewItemWidget::setDetails(QString title, QString bodyText,
       
   150         QString timeStamp, QString iconName, bool incoming, bool newMessage)
       
   151 {
       
   152     mIcon.clear();    
       
   153     mTitle.clear();
       
   154     mBodyText.clear();
       
   155     mTimeStamp.clear();
       
   156 
       
   157     mIcon.setIconName(iconName);
       
   158     mTitle = title;
       
   159     mBodyText = bodyText; 
       
   160     mTimeStamp = timeStamp;
       
   161     mIncoming = incoming;
       
   162     mNewMessage = newMessage;
       
   163 
       
   164     recreatePrimitives();
       
   165 }