phonebookui/pbkcommonui/src/cntcontactcardheadingitem.cpp
changeset 46 efe85016a067
parent 40 b46a585f6909
child 47 7cbcb2896f0e
equal deleted inserted replaced
40:b46a585f6909 46:efe85016a067
    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 #include <hbmainwindow.h>
    32 #include <hbtapgesture.h>
    32 #include <hbtapgesture.h>
       
    33 #include <cntuids.h>
       
    34 #include <xqsettingsmanager.h>
       
    35 #include <xqsettingskey.h>
    33 
    36 
    34 CntContactCardHeadingItem::CntContactCardHeadingItem(QGraphicsItem *parent) :
    37 CntContactCardHeadingItem::CntContactCardHeadingItem(QGraphicsItem *parent) :
    35     HbWidget(parent),
    38     HbWidget(parent),
    36     mIcon(NULL),
    39     mIcon(NULL),
    37     mSecondaryIcon(NULL),
    40     mSecondaryIcon(NULL),
    39     mPrimaryText(NULL),
    42     mPrimaryText(NULL),
    40     mSecondLineText(NULL),
    43     mSecondLineText(NULL),
    41     mSecondaryText(NULL),
    44     mSecondaryText(NULL),
    42     mMarqueeItem(NULL),
    45     mMarqueeItem(NULL),
    43     mFrameItem(NULL),
    46     mFrameItem(NULL),
    44     mPictureArea(NULL)
    47     mPictureArea(NULL),
       
    48     mIsFavorite(false),
       
    49     mIsOnline(false)
    45 {
    50 {
    46 }
    51 }
    47 
    52 
    48 CntContactCardHeadingItem::~CntContactCardHeadingItem()
    53 CntContactCardHeadingItem::~CntContactCardHeadingItem()
    49 {
    54 {
    69         }
    74         }
    70         mIcon = 0;
    75         mIcon = 0;
    71     }
    76     }
    72     
    77     
    73     if (!secondaryIcon.isNull())
    78     if (!secondaryIcon.isNull())
    74         {
    79     {
    75             if (!mSecondaryIcon)
    80         if (!mSecondaryIcon)
    76             {
    81         {
    77                 mSecondaryIcon = new HbIconItem(this);
    82             mSecondaryIcon = new HbIconItem(this);
    78                 mSecondaryIcon->setIcon(secondaryIcon);
    83             mSecondaryIcon->setIcon(secondaryIcon);
    79                 style()->setItemName(mSecondaryIcon, "secondary_icon");
    84             style()->setItemName(mSecondaryIcon, "secondary_icon");
    80             }
    85         }
    81         }
    86     }
    82         else
    87     else
    83         {
    88     {
    84             if (mSecondaryIcon)
    89         if (mSecondaryIcon)
    85             {
    90         {
    86                 delete mSecondaryIcon;
    91             delete mSecondaryIcon;
    87             }
    92         }
    88             mSecondaryIcon = 0;
    93         mSecondaryIcon = 0;
    89         }
    94     }
    90 
    95 
    91     if (!firstLineText.isNull())
    96     if (!firstLineText.isNull())
    92     {
    97     {
    93         if (!mFirstLineText)
    98         if (!mFirstLineText)
    94         {
    99         {
    95             mFirstLineText = new HbTextItem(this);
   100             mFirstLineText = new HbTextItem(this);
    96             mFirstLineText->setText(firstLineText);
   101             mFirstLineText->setText(firstLineText);
    97             mFirstLineText->setMaximumLines(1);
   102             mFirstLineText->setMaximumLines(1);
       
   103             mFirstLineText->setElideMode(Qt::ElideRight);
    98             style()->setItemName(mFirstLineText, "first_line_text");
   104             style()->setItemName(mFirstLineText, "first_line_text");
    99         }
   105         }
   100     }
   106     }
   101     else
   107     else
   102     {
   108     {
   113         {
   119         {
   114             mPrimaryText = new HbTextItem(this);
   120             mPrimaryText = new HbTextItem(this);
   115             mPrimaryText->setText(primaryText);
   121             mPrimaryText->setText(primaryText);
   116             mPrimaryText->setMaximumLines(2);
   122             mPrimaryText->setMaximumLines(2);
   117             mPrimaryText->setTextWrapping(Hb::TextWordWrap);
   123             mPrimaryText->setTextWrapping(Hb::TextWordWrap);
       
   124             mPrimaryText->setElideMode(Qt::ElideRight);
   118             style()->setItemName(mPrimaryText, "primary_text");
   125             style()->setItemName(mPrimaryText, "primary_text");
   119         }
   126         }
   120     }
   127     }
   121     else
   128     else
   122     {
   129     {
   220         mIcon->setIcon(icon);
   227         mIcon->setIcon(icon);
   221         repolish();
   228         repolish();
   222     }
   229     }
   223 }
   230 }
   224 
   231 
   225 void CntContactCardHeadingItem::setSecondaryIcon(bool favoriteContact)
   232 void CntContactCardHeadingItem::setFavoriteStatus(bool favoriteContact)
   226 {
   233 {
   227     secondaryIcon.clear();
   234     if (favoriteContact != mIsFavorite)
   228 
   235     {
   229     if (favoriteContact)
   236         mIsFavorite = favoriteContact;
   230     {
   237         
   231         secondaryIcon = HbIcon("qtg_small_favorite");
   238         if (!mIsOnline)
   232         createPrimitives();
   239         {
   233         mSecondaryIcon->setIcon(secondaryIcon);
   240             setSecondaryIcon();
   234     }
   241         }
   235     else
   242     }
   236     {
       
   237         createPrimitives();
       
   238     }
       
   239     repolish();
       
   240 
       
   241 }
   243 }
   242 
   244 
   243 void CntContactCardHeadingItem::recreatePrimitives()
   245 void CntContactCardHeadingItem::recreatePrimitives()
   244 {
   246 {
   245     HbWidget::recreatePrimitives();
   247     HbWidget::recreatePrimitives();
   297     primaryText.clear();
   299     primaryText.clear();
   298     firstLineText.clear();
   300     firstLineText.clear();
   299     secondaryText.clear();
   301     secondaryText.clear();
   300     icon.clear();
   302     icon.clear();
   301     tinyMarqueeText.clear();
   303     tinyMarqueeText.clear();
       
   304     secondaryIcon.clear();
   302 
   305 
   303     // icon label
   306     // icon label
   304     icon = HbIcon("qtg_large_add_contact_picture");
   307     icon = HbIcon("qtg_large_add_contact_picture");
   305 
   308 
   306     QContactName name = contact->detail<QContactName>();
   309     QContactName name = contact->detail<QContactName>();
   307 
   310 
   308     // name label
   311     // name label
   309     if (isNickName(contact) || isCompanyName(contact))
   312     if (isNickName(contact) || isCompanyName(contact))
   310     {
   313     {
   311         // prefix, first, middle, last and suffix
   314         firstLineText = createNameText(name);
   312         QStringList nameList;
       
   313         nameList << name.prefix() << name.firstName() << name.middleName() << name.lastName() << name.suffix();
       
   314         firstLineText = nameList.join(" ").trimmed();
       
   315         if (firstLineText.isEmpty())
   315         if (firstLineText.isEmpty())
   316         {
   316         {
   317             firstLineText = hbTrId("txt_phob_list_unnamed");
   317             firstLineText = hbTrId("txt_phob_list_unnamed");
   318         }
   318         }
   319     }
   319     }
   320     else
   320     else
   321     {
   321     {
   322         // prefix, first, middle, last and suffix
   322         primaryText = createNameText(name);
   323         QStringList nameList;
       
   324         nameList << name.prefix() << name.firstName() << name.middleName() << name.lastName() << name.suffix();
       
   325         primaryText = nameList.join(" ").trimmed();
       
   326         if (primaryText.isEmpty())
   323         if (primaryText.isEmpty())
   327         {
   324         {
   328             primaryText = hbTrId("txt_phob_list_unnamed");
   325             primaryText = hbTrId("txt_phob_list_unnamed");
   329         }
   326         }
   330     }
   327     }
   345     }
   342     }
   346 
   343 
   347     recreatePrimitives();
   344     recreatePrimitives();
   348 }
   345 }
   349 
   346 
       
   347 QString CntContactCardHeadingItem::createNameText(const QContactName name)
       
   348 {
       
   349     XQSettingsManager settingsMng;
       
   350     XQSettingsKey nameOrderKey(XQSettingsKey::TargetCentralRepository,
       
   351                              KCRUiContacts.iUid,
       
   352                              KCntNameOrdering);
       
   353     int setting = settingsMng.readItemValue(nameOrderKey, XQSettingsManager::TypeInt).toInt();
       
   354     
       
   355     QStringList nameList;
       
   356     QString last;
       
   357     
       
   358     switch( setting ) {
       
   359         case CntOrderLastFirst:
       
   360             nameList << name.prefix() << name.lastName() << name.firstName() << name.middleName() << name.suffix();
       
   361             break;
       
   362         case CntOrderLastCommaFirst:
       
   363             if (!name.lastName().isEmpty())
       
   364                 last = name.lastName() + ",";
       
   365             nameList << name.prefix() << last << name.firstName() << name.middleName() << name.suffix();
       
   366             break;
       
   367         default:    // Default to first name last name
       
   368             nameList << name.prefix() << name.firstName() << name.middleName() << name.lastName() << name.suffix();
       
   369             break;
       
   370     }
       
   371     
       
   372     nameList.removeAll("");
       
   373     return nameList.join(" ").trimmed();
       
   374 }
       
   375 
   350 void CntContactCardHeadingItem::setGroupDetails(const QContact* contact)
   376 void CntContactCardHeadingItem::setGroupDetails(const QContact* contact)
   351 {
   377 {
   352     firstLineText.clear();
   378     firstLineText.clear();
   353     secondaryText.clear();
   379     secondaryText.clear();
   354     icon.clear();
   380     icon.clear();
   375 }
   401 }
   376 
   402 
   377 void CntContactCardHeadingItem::processShortPress(const QPointF &point)
   403 void CntContactCardHeadingItem::processShortPress(const QPointF &point)
   378 {
   404 {
   379     emit passShortPressed(point);
   405     emit passShortPressed(point);
       
   406 }
       
   407 
       
   408 void CntContactCardHeadingItem::setOnlineStatus(bool online)
       
   409 {
       
   410     if (online != mIsOnline)
       
   411     {
       
   412         mIsOnline = online;
       
   413         
       
   414         setSecondaryIcon();
       
   415     }
   380 }
   416 }
   381 
   417 
   382 void CntContactCardHeadingItem::gestureEvent(QGestureEvent* event)
   418 void CntContactCardHeadingItem::gestureEvent(QGestureEvent* event)
   383 {
   419 {
   384     
   420     
   407     {
   443     {
   408         event->ignore();
   444         event->ignore();
   409     }
   445     }
   410 }
   446 }
   411 
   447 
   412 void CntContactCardHeadingItem::initGesture()
       
   413 {
       
   414     grabGesture(Qt::TapGesture);
       
   415 }
       
   416 
       
   417 QVariant CntContactCardHeadingItem::itemChange(GraphicsItemChange change, const QVariant &value)
   448 QVariant CntContactCardHeadingItem::itemChange(GraphicsItemChange change, const QVariant &value)
   418 {      
   449 {      
   419     if (change == QGraphicsItem::ItemSceneHasChanged)
   450     if (change == QGraphicsItem::ItemSceneHasChanged)
   420     {
   451     {
   421         HbMainWindow *window = mainWindow();
   452         HbMainWindow *window = mainWindow();
   436 {
   467 {
   437     recreatePrimitives();
   468     recreatePrimitives();
   438     repolish();
   469     repolish();
   439 }
   470 }
   440 
   471 
       
   472 void CntContactCardHeadingItem::initGesture()
       
   473 {
       
   474     grabGesture(Qt::TapGesture);
       
   475 }
       
   476 
       
   477 void CntContactCardHeadingItem::setSecondaryIcon()
       
   478 {
       
   479     if (mIsOnline)
       
   480     {
       
   481         secondaryIcon = HbIcon("qtg_small_online");
       
   482         createPrimitives();
       
   483         mSecondaryIcon->setIcon(secondaryIcon);
       
   484     }
       
   485     else if (!mIsOnline && mIsFavorite)
       
   486     {
       
   487         secondaryIcon = HbIcon("qtg_small_favorite");
       
   488         createPrimitives();
       
   489         mSecondaryIcon->setIcon(secondaryIcon);
       
   490     }
       
   491     else
       
   492     {
       
   493         secondaryIcon.clear();
       
   494         createPrimitives();
       
   495     }
       
   496 
       
   497     repolish();
       
   498 }
   441 
   499 
   442 // EOF
   500 // EOF
   443