phonebookui/pbkcommonui/src/cntcontactcardheadingitem.cpp
changeset 27 de1630741fbe
parent 25 76a2435edfd4
child 31 2a11b5b00470
equal deleted inserted replaced
25:76a2435edfd4 27:de1630741fbe
    26 #include <hbframedrawer.h>
    26 #include <hbframedrawer.h>
    27 #include <hbframeitem.h>
    27 #include <hbframeitem.h>
    28 #include <hbstyleloader.h>
    28 #include <hbstyleloader.h>
    29 #include <hbtoucharea.h>
    29 #include <hbtoucharea.h>
    30 #include <hbaction.h>
    30 #include <hbaction.h>
       
    31 #include <hbmainwindow.h>
    31 
    32 
    32 CntContactCardHeadingItem::CntContactCardHeadingItem(QGraphicsItem *parent) :
    33 CntContactCardHeadingItem::CntContactCardHeadingItem(QGraphicsItem *parent) :
    33     HbWidget(parent),
    34     HbWidget(parent),
    34     mIcon(0),
    35     mIcon(NULL),
    35     mFirstLineText(0),
    36     mSecondaryIcon(NULL),
    36     mPrimaryText(0),
    37     mFirstLineText(NULL),
    37     mSecondLineText(0),
    38     mPrimaryText(NULL),
    38     mSecondaryText(0),
    39     mSecondLineText(NULL),
    39     mMarqueeItem(0),
    40     mSecondaryText(NULL),
    40     mFrameItem(0),
    41     mMarqueeItem(NULL),
    41     mGestureFilter(0),
    42     mFrameItem(NULL),
    42     mGestureLongpressed(0),
    43     mGestureFilter(NULL),
    43     mPictureArea(0)
    44     mGestureLongpressed(NULL),
       
    45     mPictureArea(NULL)
    44 {
    46 {
    45 
    47 
    46 }
    48 }
    47 
    49 
    48 CntContactCardHeadingItem::~CntContactCardHeadingItem()
    50 CntContactCardHeadingItem::~CntContactCardHeadingItem()
    52 
    54 
    53 void CntContactCardHeadingItem::createPrimitives()
    55 void CntContactCardHeadingItem::createPrimitives()
    54 {
    56 {
    55     if (!icon.isNull())
    57     if (!icon.isNull())
    56     {
    58     {
    57         if (!mIcon)
    59         if (!mIcon && mainWindow()->orientation() != Qt::Horizontal)
    58         {
    60         {
    59             mIcon = new HbIconItem(this);
    61             mIcon = new HbIconItem(this);
    60             mIcon->setIcon(icon);
    62             mIcon->setIcon(icon);
    61             style()->setItemName(mIcon, "icon");
    63             style()->setItemName(mIcon, "icon");
    62         }
    64         }
    67         {
    69         {
    68             delete mIcon;
    70             delete mIcon;
    69         }
    71         }
    70         mIcon = 0;
    72         mIcon = 0;
    71     }
    73     }
       
    74     
       
    75     if (!secondaryIcon.isNull())
       
    76         {
       
    77             if (!mSecondaryIcon)
       
    78             {
       
    79                 mSecondaryIcon = new HbIconItem(this);
       
    80                 mSecondaryIcon->setIcon(secondaryIcon);
       
    81                 style()->setItemName(mSecondaryIcon, "secondary_icon");
       
    82             }
       
    83         }
       
    84         else
       
    85         {
       
    86             if (mSecondaryIcon)
       
    87             {
       
    88                 delete mSecondaryIcon;
       
    89             }
       
    90             mSecondaryIcon = 0;
       
    91         }
    72 
    92 
    73     if (!firstLineText.isNull())
    93     if (!firstLineText.isNull())
    74     {
    94     {
    75         if (!mFirstLineText)
    95         if (!mFirstLineText)
    76         {
    96         {
   170     }
   190     }
   171 
   191 
   172     if (!mFrameItem)
   192     if (!mFrameItem)
   173     {
   193     {
   174         mFrameItem = new HbFrameItem(this);
   194         mFrameItem = new HbFrameItem(this);
   175         mFrameItem->frameDrawer().setFrameGraphicsName("qtg_fr_groupbox");
   195         mFrameItem->frameDrawer().setFrameGraphicsName("qtg_fr_list_parent_normal");
   176         mFrameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
   196         mFrameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
   177         mFrameItem->setZValue(-2);
   197         mFrameItem->setZValue(-2);
   178         style()->setItemName(mFrameItem, "background");
   198         style()->setItemName(mFrameItem, "background");
   179     }
   199     }
   180     
   200     
   181 
   201     if (!mPictureArea) 
   182     if (!mPictureArea) {
   202     {
   183         mPictureArea = new HbTouchArea(this);
   203         mPictureArea = new HbTouchArea(this);
   184         style()->setItemName(mPictureArea, "pictureArea");
   204         style()->setItemName(mPictureArea, "pictureArea");
   185         }
   205     }
   186 
   206 
   187     initGesture();
   207     if ( mainWindow()->orientation() != Qt::Horizontal)
       
   208     {
       
   209         initGesture();
       
   210     }
   188 }
   211 }
   189 
   212 
   190 void CntContactCardHeadingItem::setIcon(const HbIcon newIcon)
   213 void CntContactCardHeadingItem::setIcon(const HbIcon newIcon)
   191 {
   214 {
   192     if (newIcon != icon)
   215     if (newIcon != icon && mainWindow()->orientation() != Qt::Horizontal)
   193     {
   216     {
   194         icon = newIcon;
   217         icon = newIcon;
   195         createPrimitives();
   218         createPrimitives();
   196         mIcon->setIcon(icon);
   219         mIcon->setIcon(icon);
   197         repolish();
   220         repolish();
   198     }
   221     }
   199 }
   222 }
   200 
   223 
       
   224 void CntContactCardHeadingItem::setSecondaryIcon(bool favoriteContact)
       
   225 {
       
   226     secondaryIcon.clear();
       
   227 
       
   228     if (favoriteContact)
       
   229     {
       
   230         secondaryIcon = HbIcon("qtg_small_favorite");
       
   231         createPrimitives();
       
   232         mSecondaryIcon->setIcon(secondaryIcon);
       
   233     }
       
   234     else
       
   235     {
       
   236         createPrimitives();
       
   237     }
       
   238     repolish();
       
   239 
       
   240 }
       
   241 
   201 void CntContactCardHeadingItem::recreatePrimitives()
   242 void CntContactCardHeadingItem::recreatePrimitives()
   202 {
   243 {
   203     HbWidget::recreatePrimitives();
   244     HbWidget::recreatePrimitives();
   204 
   245 
   205     delete mIcon;
   246     delete mIcon;
   206     mIcon = 0;
   247     mIcon = 0;
       
   248     
       
   249     delete mSecondaryIcon;
       
   250     mSecondaryIcon = 0;
   207 
   251 
   208     delete mFirstLineText;
   252     delete mFirstLineText;
   209     mFirstLineText = 0;
   253     mFirstLineText = 0;
   210 
   254 
   211     delete mPrimaryText;
   255     delete mPrimaryText;
   240     return !(contact->detail<QContactNickname>().nickname().isNull());
   284     return !(contact->detail<QContactNickname>().nickname().isNull());
   241 }
   285 }
   242 
   286 
   243 bool CntContactCardHeadingItem::isCompanyName(const QContact* contact)
   287 bool CntContactCardHeadingItem::isCompanyName(const QContact* contact)
   244 {
   288 {
   245     return (!(contact->detail<QContactOrganization>().title().isNull()) || !(contact->detail<QContactOrganization>().name().isNull()));
   289     return (!(contact->detail<QContactOrganization>().title().isNull()) 
   246 }
   290         || !(contact->detail<QContactOrganization>().name().isNull())
   247 
   291         || !(contact->detail<QContactOrganization>().department().isEmpty()));
   248 void CntContactCardHeadingItem::setDetails(const QContact* contact)
   292 }
       
   293 
       
   294 void CntContactCardHeadingItem::setDetails(const QContact* contact, bool isMyCard)
   249 {
   295 {
   250     primaryText.clear();
   296     primaryText.clear();
   251     firstLineText.clear();
   297     firstLineText.clear();
   252     secondaryText.clear();
   298     secondaryText.clear();
   253     icon.clear();
   299     icon.clear();
   254     tinyMarqueeText.clear();
   300     tinyMarqueeText.clear();
   255 
   301 
   256     // icon label
   302     // icon label
   257     icon = HbIcon("qtg_large_avatar");
   303     if (isMyCard)
       
   304     {
       
   305         icon = HbIcon("qtg_large_mycard");
       
   306     }
       
   307     else
       
   308     {
       
   309         icon = HbIcon("qtg_large_avatar");
       
   310     }
   258 
   311 
   259     QContactName name = contact->detail<QContactName>();
   312     QContactName name = contact->detail<QContactName>();
   260 
   313 
   261     // name label
   314     // name label
   262     if (isNickName(contact) || isCompanyName(contact))
   315     if (isNickName(contact) || isCompanyName(contact))
   265         QStringList nameList;
   318         QStringList nameList;
   266         nameList << name.prefix() << name.firstName() << name.middleName() << name.lastName() << name.suffix();
   319         nameList << name.prefix() << name.firstName() << name.middleName() << name.lastName() << name.suffix();
   267         firstLineText = nameList.join(" ").trimmed();
   320         firstLineText = nameList.join(" ").trimmed();
   268         if (firstLineText.isEmpty())
   321         if (firstLineText.isEmpty())
   269         {
   322         {
   270             firstLineText = hbTrId("Unnamed");
   323             firstLineText = hbTrId("txt_phob_list_unnamed");
   271         }
   324         }
   272     }
   325     }
   273     else
   326     else
   274     {
   327     {
   275         // prefix, first, middle, last and suffix
   328         // prefix, first, middle, last and suffix
   276         QStringList nameList;
   329         QStringList nameList;
   277         nameList << name.prefix() << name.firstName() << name.middleName() << name.lastName() << name.suffix();
   330         nameList << name.prefix() << name.firstName() << name.middleName() << name.lastName() << name.suffix();
   278         primaryText = nameList.join(" ").trimmed();
   331         primaryText = nameList.join(" ").trimmed();
   279         if (primaryText.isEmpty())
   332         if (primaryText.isEmpty())
   280         {
   333         {
   281             primaryText = hbTrId("Unnamed");
   334             primaryText = hbTrId("txt_phob_list_unnamed");
   282         }
   335         }
   283         
   336         
   284         /*
   337         /*
   285         // prefix, first and middle
   338         // prefix, first and middle
   286         QStringList firstNameList;
   339         QStringList firstNameList;
   326 
   379 
   327     primaryText = groupName;
   380     primaryText = groupName;
   328     
   381     
   329     if (primaryText.isEmpty())
   382     if (primaryText.isEmpty())
   330     {
   383     {
   331         primaryText = hbTrId("Unnamed");
   384         primaryText = hbTrId("txt_phob_list_unnamed");
   332     }
   385     }
   333        
   386        
   334     recreatePrimitives();
   387     recreatePrimitives();
   335 }
   388 }
   336 
   389 
   366     // need to worry about deleting the gesture. 
   419     // need to worry about deleting the gesture. 
   367     mGestureLongpressed = new HbGesture(HbGesture::longpress, 5);
   420     mGestureLongpressed = new HbGesture(HbGesture::longpress, 5);
   368     mGestureFilter->addGesture(mGestureLongpressed);
   421     mGestureFilter->addGesture(mGestureLongpressed);
   369     mGestureFilter->setLongpressAnimation(true);
   422     mGestureFilter->setLongpressAnimation(true);
   370     
   423     
   371     installSceneEventFilter(mGestureFilter);
   424     mIcon->installSceneEventFilter(mGestureFilter);
   372     connect(mGestureLongpressed, SIGNAL(longPress(QPointF)), this, SLOT(processLongPress(QPointF)));    
   425     connect(mGestureLongpressed, SIGNAL(longPress(QPointF)), this, SLOT(processLongPress(QPointF)));    
   373 }
   426 }
   374 
   427 
       
   428 QVariant CntContactCardHeadingItem::itemChange(GraphicsItemChange change, const QVariant &value)
       
   429 {
       
   430     if (change == QGraphicsItem::ItemSceneHasChanged)
       
   431     {
       
   432         HbMainWindow *window = mainWindow();
       
   433         if (window)
       
   434         {
       
   435             connect(window, SIGNAL(orientationChanged(Qt::Orientation)), 
       
   436                 this, SLOT(orientationChanged(Qt::Orientation)));
       
   437         }
       
   438         else
       
   439         {
       
   440             QObject::disconnect(this, SLOT(orientationChanged(Qt::Orientation)));
       
   441         }
       
   442     }
       
   443     return HbWidget::itemChange(change, value);
       
   444 }
       
   445 
       
   446 void CntContactCardHeadingItem::orientationChanged(Qt::Orientation)
       
   447 {
       
   448     recreatePrimitives();
       
   449     repolish();
       
   450 }
       
   451 
       
   452 
   375 // EOF
   453 // EOF
   376 
   454