contactwidgethsplugin/contactwidgeths/src/contactwidgeths.cpp
changeset 53 e6aff7b69165
parent 51 81c360d47083
child 66 554fe4dbbb59
equal deleted inserted replaced
51:81c360d47083 53:e6aff7b69165
   133 /*!
   133 /*!
   134     Destructor
   134     Destructor
   135 */
   135 */
   136 ContactWidgetHs::~ContactWidgetHs()
   136 ContactWidgetHs::~ContactWidgetHs()
   137 {
   137 {
   138     delete mLauncher;
   138 	if (mLauncher) 
   139     delete mContactManager;
   139 		{
   140     delete mAppManager;
   140 		delete mLauncher;
   141     delete mAvatar;	
   141 		}
   142     // Deleting request cancels all pending requests 
   142     if (mContactManager)
   143     delete mContactSelectRequest;
   143     	{
   144     //,,first cancel?
   144     	delete mContactManager;
   145     delete mThumbnailManager;
   145     	}
   146     delete mTranslator;
   146     if (mAppManager)
       
   147     	{
       
   148     	delete mAppManager;
       
   149     	}
       
   150     if (mAvatar)
       
   151     	{
       
   152     	delete mAvatar;
       
   153     	}
       
   154     
       
   155     // Deleting request cancels all pending requests
       
   156     if (mContactSelectRequest)
       
   157     	{
       
   158     	delete mContactSelectRequest;
       
   159     	}
       
   160     
       
   161     if (mThumbnailManager)
       
   162     	{
       
   163     	delete mThumbnailManager;
       
   164     	}
       
   165     if (mTranslator)
       
   166     	{
       
   167     	delete mTranslator;
       
   168     	}
   147 }
   169 }
   148 
   170 
   149 /*!
   171 /*!
   150     Updates the UI based on data from current contact
   172     Updates the UI based on data from current contact
   151 */
   173 */
   238     QStyleOptionGraphicsItem *item = new QStyleOptionGraphicsItem;
   260     QStyleOptionGraphicsItem *item = new QStyleOptionGraphicsItem;
   239     avatarDrawer->paint(&painter, QRectF(0, 0, contactIconSize, contactIconSize));
   261     avatarDrawer->paint(&painter, QRectF(0, 0, contactIconSize, contactIconSize));
   240     painter.end();
   262     painter.end();
   241     qDebug() << "setContactImage av 2"; //,,             
   263     qDebug() << "setContactImage av 2"; //,,             
   242 
   264 
       
   265     int maxSize = (inputPixmap.width() > inputPixmap.height() ? inputPixmap.width():inputPixmap.height());
       
   266     int minSize = (inputPixmap.width() < inputPixmap.height() ? inputPixmap.width():inputPixmap.height());
       
   267     int sizeFrom = maxSize - minSize;
   243     // We may draw the icon when thumnail processing is still in progress, 
   268     // We may draw the icon when thumnail processing is still in progress, 
   244     // so can't show the thumbnail yet.
   269     // so can't show the thumbnail yet.
   245 	if (inputPixmap.width()>0) {
   270 	if (inputPixmap.width()>0) {
       
   271 		if (inputPixmap.width() < inputPixmap.height())
       
   272 		{
       
   273   		QPixmap pm3 = inputPixmap.copy(0,sizeFrom/2,minSize,minSize);
       
   274   		QPixmap pm2 = pm3.scaled( QSize(contactIconSize, contactIconSize), Qt::KeepAspectRatio );
       
   275   		qDebug() << "pm2 " << pm2.width() << " " << pm2.height();
       
   276   		avatarPixmap = pm2; 
       
   277 		}
       
   278 		else if (inputPixmap.width() > inputPixmap.height())
       
   279 		{
       
   280   		QPixmap pm3 = inputPixmap.copy(sizeFrom/2,0,minSize,minSize);
       
   281   		QPixmap pm2 = pm3.scaled( QSize(contactIconSize, contactIconSize), Qt::KeepAspectRatio );
       
   282   		qDebug() << "pm2 " << pm2.width() << " " << pm2.height();
       
   283   		avatarPixmap = pm2; 
       
   284     }else
       
   285     {
   246 		QPixmap pm2 = inputPixmap.scaled( QSize(contactIconSize, contactIconSize), Qt::IgnoreAspectRatio );
   286 		QPixmap pm2 = inputPixmap.scaled( QSize(contactIconSize, contactIconSize), Qt::IgnoreAspectRatio );
   247 		qDebug() << "pm2 " << pm2.width() << " " << pm2.height();
   287 		qDebug() << "pm2 " << pm2.width() << " " << pm2.height();
   248 		avatarPixmap = pm2; //
   288 		avatarPixmap = pm2; //
       
   289     }
   249 	} 
   290 	} 
   250     
   291     
   251     HbIcon *avatarIcon = new HbIcon(QIcon(avatarPixmap));
   292     HbIcon *avatarIcon = new HbIcon(QIcon(avatarPixmap));
   252        
   293        
   253     mAvatarIconItem->setIcon(*avatarIcon);
   294     mAvatarIconItem->setIcon(*avatarIcon);
       
   295     mAvatarIconItem->setSize(QSize(contactIconSize, contactIconSize));
       
   296     mAvatarIconItem->setAspectRatioMode(Qt::KeepAspectRatio);
   254         
   297         
   255     // Then display the new image
   298     // Then display the new image
   256     update();
   299     update();
   257     qDebug() << "setContactImage av 3"; //,,
   300     qDebug() << "setContactImage av 3"; //,,
   258     
   301     
   412     Implemented to receive mouse press events.
   455     Implemented to receive mouse press events.
   413     Otherwise these events will propagate to any topmost item beneath this item.
   456     Otherwise these events will propagate to any topmost item beneath this item.
   414 */
   457 */
   415 void ContactWidgetHs::mousePressEvent(QGraphicsSceneMouseEvent *event)
   458 void ContactWidgetHs::mousePressEvent(QGraphicsSceneMouseEvent *event)
   416 {
   459 {
   417     if (event && event->type() == QEvent::GraphicsSceneMousePress) {
   460 	Q_UNUSED(event);
       
   461 }
       
   462 
       
   463 /*!
       
   464     \fn void ContactWidgetHs::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
       
   465 
       
   466     Widget start is triggered from release \a event.
       
   467     \sa 
       
   468 */
       
   469 void ContactWidgetHs::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
       
   470 {
       
   471 	qDebug() << "mouseReleaseEvent event->type() = " << (int)event->type();
       
   472 
       
   473 	//Q_UNUSED(event);
       
   474     if (event && event->type() == QEvent::GraphicsSceneMouseRelease) {
   418         // If the widget doesn't have contact yet and
   475         // If the widget doesn't have contact yet and
   419         // there are contacts, select one.    
   476         // there are contacts, select one.    
   420         if (mContactLocalId == unUsedContactId) {
   477         if (mContactLocalId == unUsedContactId) {
   421             if (contactsExist()) {				    
   478             if (contactsExist()) {				    
   422                 launchSingleContactSelecting();                  
   479                 launchSingleContactSelecting();                  
   445             qDebug() << "after exec rect() " << mLauncherRect;
   502             qDebug() << "after exec rect() " << mLauncherRect;
   446         }
   503         }
   447     }
   504     }
   448 }
   505 }
   449 
   506 
   450 /*!
       
   451     \fn void ContactWidgetHs::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
       
   452 
       
   453     Widget start is triggered from release \a event.
       
   454     \sa 
       
   455 */
       
   456 void ContactWidgetHs::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
       
   457 {
       
   458     Q_UNUSED(event);
       
   459 }
       
   460 
       
   461 
   507 
   462 // Store contact data to member variables and to UI
   508 // Store contact data to member variables and to UI
   463 void ContactWidgetHs::getContactData()
   509 void ContactWidgetHs::getContactData()
   464 {
   510 {
   465     if (!mContactManager) { 
   511     if (!mContactManager) { 
   749     qDebug() << "ContactWidgetHs::onContactsRemoved, removed count " << contactIds.count();
   795     qDebug() << "ContactWidgetHs::onContactsRemoved, removed count " << contactIds.count();
   750     int i;
   796     int i;
   751     for(i=0; i<contactIds.count(); i++) {
   797     for(i=0; i<contactIds.count(); i++) {
   752         if (contactIds.at(i) == mContactLocalId) {
   798         if (contactIds.at(i) == mContactLocalId) {
   753             qDebug() << "-deleting widget with removed contact " << mContactLocalId;
   799             qDebug() << "-deleting widget with removed contact " << mContactLocalId;
   754             // TODO this deletes the widget. Can we always delete the object immediately?
   800 
       
   801             mAvatarIconItem->deleteLater();
       
   802             mContactNameLabel->deleteLater();
       
   803             mAppManager->deleteLater();
       
   804             mLauncher->deleteLater();
       
   805             mContactLocalId = unUsedContactId;
       
   806             delete mAvatar;
       
   807             mContactHasAvatarDetail = false;
       
   808             mContactManager->deleteLater();
       
   809             mThumbnailManager->deleteLater();
       
   810             
   755             emit finished();
   811             emit finished();
   756             break;
   812             break;
   757         }
   813         }
   758     }
   814     }
   759 }
   815 }