calendarui/agendaeventviewer/src/agendaeventvieweritem.cpp
changeset 18 c198609911f9
child 26 a949c2543c15
equal deleted inserted replaced
0:f979ecb2b13e 18:c198609911f9
       
     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 
       
    30 /*!
       
    31  \class AgendaEventViewerItem
       
    32 
       
    33  This class creates all the primitives for AgendaEventViewer item.
       
    34  */
       
    35 
       
    36 /*!
       
    37  Constructor.
       
    38 
       
    39  \param parent Pointer to QGraphicsItem.
       
    40  */
       
    41 AgendaEventViewerItem::AgendaEventViewerItem(QGraphicsItem *parent) :
       
    42 	HbWidget(parent), mPrimaryText(NULL), mSecondaryText(NULL),
       
    43 	        mPrimaryIcon(NULL), mSecondaryIcon(NULL)
       
    44 {
       
    45 
       
    46 	// Path for widgetml and css files.
       
    47 	HbStyleLoader::registerFilePath(":/");
       
    48 
       
    49 }
       
    50 
       
    51 /*!
       
    52  Destructor.
       
    53  */
       
    54 AgendaEventViewerItem::~AgendaEventViewerItem()
       
    55 {
       
    56 	HbStyleLoader::unregisterFilePath(":/");
       
    57 
       
    58 }
       
    59 
       
    60 /*!
       
    61  Sets the data for EventViewer items
       
    62  To set textitem data use Qt::DisplayRole
       
    63  To set iconitem data use Qt::DecorationRole
       
    64  \param itemData string list of itemdata
       
    65  \param role qt role of text and icon item
       
    66  */
       
    67 void AgendaEventViewerItem::setEventViewerItemData(const QStringList &itemData,
       
    68                                                    int role)
       
    69 {
       
    70 	if (!itemData.isEmpty()) {
       
    71 		QString firstItemData(QString::null);
       
    72 		QString secondItemData(QString::null);
       
    73 
       
    74 		if (itemData.count() == 2) {
       
    75 			firstItemData = itemData.at(0);
       
    76 			secondItemData = itemData.at(1);
       
    77 		} else {
       
    78 			firstItemData = itemData.at(0);
       
    79 		}
       
    80 
       
    81 		if (role == Qt::DisplayRole) {
       
    82 			if (!firstItemData.isEmpty()) {
       
    83 				if (!mPrimaryText) {
       
    84 					mPrimaryText = new HbTextItem(this);
       
    85 					HbStyle::setItemName(mPrimaryText, "primaryTextItem");
       
    86 					mPrimaryText->setElideMode(Qt::ElideNone);
       
    87 				}
       
    88 				mPrimaryText->setText(firstItemData);
       
    89 			} else {
       
    90 				if (mPrimaryText) {
       
    91 					delete mPrimaryText;
       
    92 					mPrimaryText = NULL;
       
    93 				}
       
    94 			}
       
    95 
       
    96 			if (!mSecondaryText) {
       
    97 				mSecondaryText = new HbTextItem(this);
       
    98 				HbStyle::setItemName(mSecondaryText, "secondaryTextItem");
       
    99 				mSecondaryText->setTextWrapping(Hb::TextWordWrap);
       
   100 			}
       
   101 			
       
   102 			if (!secondItemData.isEmpty()) {
       
   103 				
       
   104 				mSecondaryText->setText(secondItemData);
       
   105 			} else {
       
   106 				mSecondaryText->setText("");
       
   107 				}
       
   108 		} else {
       
   109 			if (role == Qt::DecorationRole) {
       
   110 				if (!firstItemData.isEmpty()) {
       
   111 					if (!mPrimaryIcon) {
       
   112 						mPrimaryIcon = new HbIconItem(this);
       
   113 					}
       
   114 					HbStyle::setItemName(mPrimaryIcon, "primaryIconItem");
       
   115 					mPrimaryIcon->setVisible(true);
       
   116 					mPrimaryIcon->setIconName(firstItemData);
       
   117 
       
   118 				} else {
       
   119 					if (mPrimaryIcon) {
       
   120 						HbStyle::setItemName(mPrimaryIcon,"");
       
   121 						mPrimaryIcon->setVisible(false); 
       
   122 					}
       
   123 					
       
   124 				}
       
   125 				if (!secondItemData.isEmpty()) {
       
   126 					if (!mSecondaryIcon) {
       
   127 						mSecondaryIcon = new HbIconItem(this);
       
   128 						HbStyle::setItemName(mSecondaryIcon, 
       
   129 						                     "secondaryIconItem");
       
   130 					}
       
   131 					mSecondaryIcon->setIconName(secondItemData);
       
   132 
       
   133 				} else {
       
   134 					if (mSecondaryIcon) {
       
   135 						delete mSecondaryIcon;
       
   136 						mSecondaryIcon = NULL;
       
   137 					}
       
   138 
       
   139 				}
       
   140 
       
   141 			}
       
   142 		}
       
   143 	}
       
   144 	repolish();
       
   145 }
       
   146 
       
   147 // End of file	--Don't remove this.