calendarui/agendaeventviewer/src/agendaeventvieweritem.cpp
branchRCL_3
changeset 65 12af337248b1
equal deleted inserted replaced
60:96907930389d 65:12af337248b1
       
     1 /*
       
     2 * Copyright (c) 2010 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: Definition of AgendaEventViewerItem class
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtGui>
       
    19 #include <QVariant>
       
    20 
       
    21 // System Includes.
       
    22 #include <hbstyleloader.h>
       
    23 #include <hbstyle.h>
       
    24 #include <hbtextitem.h>
       
    25 #include <hbiconitem.h>
       
    26 
       
    27 // User Includes.
       
    28 #include "agendaeventvieweritem.h"
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "agendaeventvieweritemTraces.h"
       
    32 #endif
       
    33 
       
    34 
       
    35 /*!
       
    36  \class AgendaEventViewerItem
       
    37 
       
    38  This class creates all the primitives for AgendaEventViewer item.
       
    39  */
       
    40 
       
    41 /*!
       
    42  Constructor.
       
    43 
       
    44  \param parent Pointer to QGraphicsItem.
       
    45  */
       
    46 AgendaEventViewerItem::AgendaEventViewerItem(QGraphicsItem *parent) :
       
    47 	HbWidget(parent), mPrimaryText(NULL), mSecondaryText(NULL),
       
    48 	        mPrimaryIcon(NULL), mSecondaryIcon(NULL),mPrimaryRightIcon(NULL),
       
    49 	        mPrimaryLeftIcon(NULL)
       
    50 {
       
    51     OstTraceFunctionEntry0( AGENDAEVENTVIEWERITEM_AGENDAEVENTVIEWERITEM_ENTRY );
       
    52 
       
    53 	// Path for widgetml and css files.
       
    54 	HbStyleLoader::registerFilePath(":/");
       
    55 
       
    56 	OstTraceFunctionExit0( AGENDAEVENTVIEWERITEM_AGENDAEVENTVIEWERITEM_EXIT );
       
    57 }
       
    58 
       
    59 /*!
       
    60  Destructor.
       
    61  */
       
    62 AgendaEventViewerItem::~AgendaEventViewerItem()
       
    63 {
       
    64 	OstTraceFunctionEntry0( DUP1_AGENDAEVENTVIEWERITEM_AGENDAEVENTVIEWERITEM_ENTRY );
       
    65 	HbStyleLoader::unregisterFilePath(":/");
       
    66 
       
    67 	OstTraceFunctionExit0( DUP1_AGENDAEVENTVIEWERITEM_AGENDAEVENTVIEWERITEM_EXIT );
       
    68 }
       
    69 
       
    70 /*!
       
    71  Sets the data for EventViewer items
       
    72  To set textitem data use Qt::DisplayRole
       
    73  To set iconitem data use Qt::DecorationRole
       
    74  \param itemData string list of itemdata
       
    75  \param role qt role of text and icon item
       
    76  */
       
    77 void AgendaEventViewerItem::setEventViewerItemData(const QStringList &itemData,
       
    78                                                    int role)
       
    79 {
       
    80 	OstTraceFunctionEntry0( AGENDAEVENTVIEWERITEM_SETEVENTVIEWERITEMDATA_ENTRY );
       
    81 	if (!itemData.isEmpty()) {
       
    82 		QString firstItemData(QString::null);
       
    83 		QString secondItemData(QString::null);
       
    84 		QString thirdItemData(QString::null);
       
    85         if (itemData.count() == 2) {
       
    86             firstItemData = itemData.at(0);
       
    87             secondItemData = itemData.at(1);
       
    88         }
       
    89         else if (itemData.count() == 3) {
       
    90 			firstItemData = itemData.at(0);
       
    91 			secondItemData = itemData.at(1);
       
    92 			thirdItemData = itemData.at(2);
       
    93 		} else {
       
    94 			firstItemData = itemData.at(0);
       
    95 		}
       
    96 
       
    97 		if (role == Qt::DisplayRole) {
       
    98 			if (!firstItemData.isEmpty()) {
       
    99 				if (!mPrimaryText) {
       
   100 					mPrimaryText = new HbTextItem(this);
       
   101 					HbStyle::setItemName(mPrimaryText, "primaryTextItem");
       
   102 					mPrimaryText->setElideMode(Qt::ElideNone);
       
   103 				}
       
   104 				mPrimaryText->setText(firstItemData);
       
   105 			} else {
       
   106 				if (mPrimaryText) {
       
   107 					delete mPrimaryText;
       
   108 					mPrimaryText = NULL;
       
   109 				}
       
   110 			}
       
   111 
       
   112 			if (!mSecondaryText) {
       
   113 				mSecondaryText = new HbTextItem(this);
       
   114 				HbStyle::setItemName(mSecondaryText, "secondaryTextItem");
       
   115 				mSecondaryText->setTextWrapping(Hb::TextWordWrap);
       
   116 			}
       
   117 			
       
   118 			if (!secondItemData.isEmpty()) {
       
   119 				
       
   120 				mSecondaryText->setText(secondItemData);
       
   121 			} else {
       
   122 				mSecondaryText->setText("");
       
   123 				}
       
   124 		} else {
       
   125 			if (role == Qt::DecorationRole) {
       
   126                if (!firstItemData.isEmpty()) {
       
   127                    if (!mPrimaryLeftIcon) {
       
   128                    mPrimaryLeftIcon = new HbIconItem(this);
       
   129                    }
       
   130                    HbStyle::setItemName(mPrimaryLeftIcon, "primaryLeftIconItem");
       
   131                    mPrimaryLeftIcon->setVisible(true);
       
   132                    mPrimaryLeftIcon->setIconName(firstItemData);
       
   133 
       
   134                } else {
       
   135                    if (mPrimaryLeftIcon) {
       
   136                        HbStyle::setItemName(mPrimaryLeftIcon,"");
       
   137                        mPrimaryLeftIcon->setVisible(false); 
       
   138                    }
       
   139                    
       
   140                }
       
   141 				if (!secondItemData.isEmpty()) {
       
   142 					if (!mPrimaryRightIcon) {
       
   143 					mPrimaryRightIcon = new HbIconItem(this);
       
   144 					}
       
   145 					HbStyle::setItemName(mPrimaryRightIcon, "primaryRightIconItem");
       
   146 					mPrimaryRightIcon->setVisible(true);
       
   147 					mPrimaryRightIcon->setIconName(secondItemData);
       
   148 
       
   149 				} else {
       
   150 					if (mPrimaryRightIcon) {
       
   151 						HbStyle::setItemName(mPrimaryRightIcon,"");
       
   152 						mPrimaryRightIcon->setVisible(false); 
       
   153 					}
       
   154 					
       
   155 				}
       
   156 				if (!thirdItemData.isEmpty()) {
       
   157 					if (!mSecondaryIcon) {
       
   158 						mSecondaryIcon = new HbIconItem(this);
       
   159 						HbStyle::setItemName(mSecondaryIcon, 
       
   160 						                     "secondaryIconItem");
       
   161 					}
       
   162 					mSecondaryIcon->setIconName(thirdItemData);
       
   163 
       
   164 				} else {
       
   165 					if (mSecondaryIcon) {
       
   166 						delete mSecondaryIcon;
       
   167 						mSecondaryIcon = NULL;
       
   168 					}
       
   169 
       
   170 				}
       
   171 
       
   172 			}
       
   173 		}
       
   174 	}
       
   175 	repolish();
       
   176 	OstTraceFunctionExit0( AGENDAEVENTVIEWERITEM_SETEVENTVIEWERITEMDATA_EXIT );
       
   177 }
       
   178 
       
   179 // End of file	--Don't remove this.