39 |
39 |
40 #include "contactwidgeths.h" |
40 #include "contactwidgeths.h" |
41 #include "commlauncherwidget.h" |
41 #include "commlauncherwidget.h" |
42 #include "ihswidgetpreferenceservice.h" |
42 #include "ihswidgetpreferenceservice.h" |
43 |
43 |
|
44 const QString translationsPath = "/resource/qt/translations/"; |
|
45 const QString translationsFile = "contactwidgethsplugin"; |
|
46 |
44 const QString defaultAvatar = "qtg_large_avatar"; |
47 const QString defaultAvatar = "qtg_large_avatar"; |
45 const QString addContactAvatar = "qtg_small_add"; |
48 const QString addContactAvatar = "qtg_small_add"; |
46 const QString normalFrameName = "qtg_fr_hsshortcut_normal"; |
49 const QString normalFrameName = "qtg_fr_hsshortcut_normal"; |
47 const QString normalTextColor = "qtc_hs_list_item_title_normal"; |
50 const QString normalTextColor = "qtc_hs_list_item_title_normal"; |
48 const QString latchedFrameName = "qtg_fr_hsitems_latched"; |
51 const QString latchedFrameName = "qtg_fr_hsitems_latched"; |
77 mThumbnailPixmap(QPixmap()), |
80 mThumbnailPixmap(QPixmap()), |
78 mThumbnailInProgress(false), |
81 mThumbnailInProgress(false), |
79 mTranslator(0) |
82 mTranslator(0) |
80 { |
83 { |
81 // Localization file loading |
84 // Localization file loading |
82 mTranslator = new HbTranslator(); |
85 mTranslator = new HbTranslator(translationsPath, translationsFile); |
83 mTranslator->loadCommon(); |
86 mTranslator->loadCommon(); |
84 |
87 |
85 // UI creation done in onInitialize() |
88 // UI creation done in onInitialize() |
86 if (mainWindow()) { |
89 if (mainWindow()) { |
87 mMainWindow = mainWindow(); |
90 mMainWindow = mainWindow(); |
130 /*! |
133 /*! |
131 Destructor |
134 Destructor |
132 */ |
135 */ |
133 ContactWidgetHs::~ContactWidgetHs() |
136 ContactWidgetHs::~ContactWidgetHs() |
134 { |
137 { |
135 delete mLauncher; |
138 if (mLauncher) |
136 delete mContactManager; |
139 { |
137 delete mAppManager; |
140 delete mLauncher; |
138 delete mAvatar; |
141 } |
139 // Deleting request cancels all pending requests |
142 if (mContactManager) |
140 delete mContactSelectRequest; |
143 { |
141 //,,first cancel? |
144 delete mContactManager; |
142 delete mThumbnailManager; |
145 } |
143 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 } |
144 } |
169 } |
145 |
170 |
146 /*! |
171 /*! |
147 Updates the UI based on data from current contact |
172 Updates the UI based on data from current contact |
148 */ |
173 */ |
235 QStyleOptionGraphicsItem *item = new QStyleOptionGraphicsItem; |
260 QStyleOptionGraphicsItem *item = new QStyleOptionGraphicsItem; |
236 avatarDrawer->paint(&painter, QRectF(0, 0, contactIconSize, contactIconSize)); |
261 avatarDrawer->paint(&painter, QRectF(0, 0, contactIconSize, contactIconSize)); |
237 painter.end(); |
262 painter.end(); |
238 qDebug() << "setContactImage av 2"; //,, |
263 qDebug() << "setContactImage av 2"; //,, |
239 |
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; |
240 // 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, |
241 // so can't show the thumbnail yet. |
269 // so can't show the thumbnail yet. |
242 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 { |
243 QPixmap pm2 = inputPixmap.scaled( QSize(contactIconSize, contactIconSize), Qt::IgnoreAspectRatio ); |
286 QPixmap pm2 = inputPixmap.scaled( QSize(contactIconSize, contactIconSize), Qt::IgnoreAspectRatio ); |
244 qDebug() << "pm2 " << pm2.width() << " " << pm2.height(); |
287 qDebug() << "pm2 " << pm2.width() << " " << pm2.height(); |
245 avatarPixmap = pm2; // |
288 avatarPixmap = pm2; // |
|
289 } |
246 } |
290 } |
247 |
291 |
248 HbIcon *avatarIcon = new HbIcon(QIcon(avatarPixmap)); |
292 HbIcon *avatarIcon = new HbIcon(QIcon(avatarPixmap)); |
249 |
293 |
250 mAvatarIconItem->setIcon(*avatarIcon); |
294 mAvatarIconItem->setIcon(*avatarIcon); |
|
295 mAvatarIconItem->setSize(QSize(contactIconSize, contactIconSize)); |
|
296 mAvatarIconItem->setAspectRatioMode(Qt::KeepAspectRatio); |
251 |
297 |
252 // Then display the new image |
298 // Then display the new image |
253 update(); |
299 update(); |
254 qDebug() << "setContactImage av 3"; //,, |
300 qDebug() << "setContactImage av 3"; //,, |
255 |
301 |
409 Implemented to receive mouse press events. |
455 Implemented to receive mouse press events. |
410 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. |
411 */ |
457 */ |
412 void ContactWidgetHs::mousePressEvent(QGraphicsSceneMouseEvent *event) |
458 void ContactWidgetHs::mousePressEvent(QGraphicsSceneMouseEvent *event) |
413 { |
459 { |
414 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) { |
415 // If the widget doesn't have contact yet and |
475 // If the widget doesn't have contact yet and |
416 // there are contacts, select one. |
476 // there are contacts, select one. |
417 if (mContactLocalId == unUsedContactId) { |
477 if (mContactLocalId == unUsedContactId) { |
418 if (contactsExist()) { |
478 if (contactsExist()) { |
419 launchSingleContactSelecting(); |
479 launchSingleContactSelecting(); |
577 Called when the widget is hidden. |
626 Called when the widget is hidden. |
578 This method is needed. Otherwise the widget cannot be added to HS. |
627 This method is needed. Otherwise the widget cannot be added to HS. |
579 */ |
628 */ |
580 void ContactWidgetHs::onHide() |
629 void ContactWidgetHs::onHide() |
581 { |
630 { |
582 qDebug() << "ContactWidgetHs::onHide()"; |
631 qDebug() << "ContactWidgetHs::onHide()"; |
|
632 // close the launcher if it's open |
|
633 if (mLauncher->isVisible()) { |
|
634 mLauncher->close(); |
|
635 } |
583 } |
636 } |
584 |
637 |
585 |
638 |
586 /*! |
639 /*! |
587 Orientation changed slot |
640 Orientation changed slot |
742 qDebug() << "ContactWidgetHs::onContactsRemoved, removed count " << contactIds.count(); |
795 qDebug() << "ContactWidgetHs::onContactsRemoved, removed count " << contactIds.count(); |
743 int i; |
796 int i; |
744 for(i=0; i<contactIds.count(); i++) { |
797 for(i=0; i<contactIds.count(); i++) { |
745 if (contactIds.at(i) == mContactLocalId) { |
798 if (contactIds.at(i) == mContactLocalId) { |
746 qDebug() << "-deleting widget with removed contact " << mContactLocalId; |
799 qDebug() << "-deleting widget with removed contact " << mContactLocalId; |
747 // 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 |
748 emit finished(); |
811 emit finished(); |
749 break; |
812 break; |
750 } |
813 } |
751 } |
814 } |
752 } |
815 } |