15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "cntimagelabel.h" |
18 #include "cntimagelabel.h" |
19 |
19 |
|
20 #include <QPainter> |
|
21 #include <QGraphicsDropShadowEffect> |
|
22 |
20 #include <hbinstantfeedback.h> |
23 #include <hbinstantfeedback.h> |
21 #include <hbtapgesture.h> |
24 #include <hbtapgesture.h> |
22 #include <hbeffect.h> |
25 #include <hbeffect.h> |
23 #include <QGraphicsSceneMouseEvent> |
26 #include <hbdeviceprofile.h> |
|
27 #include <hbiconitem.h> |
|
28 #include <hbicon.h> |
|
29 #include <hbstyle.h> |
24 |
30 |
|
31 static const qreal ImageRounding = 1.5; // units |
|
32 |
|
33 /* |
|
34 * Imagel label for landscape views. |
|
35 */ |
25 CntImageLabel::CntImageLabel(QGraphicsItem *parent) : |
36 CntImageLabel::CntImageLabel(QGraphicsItem *parent) : |
26 HbLabel(parent) |
37 HbWidget(parent) |
27 { |
38 { |
|
39 setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
40 |
|
41 mDefaultAvatar = new HbIconItem(this); |
|
42 style()->setItemName(mDefaultAvatar, "icon"); |
|
43 mDefaultAvatar->setAlignment(Qt::AlignCenter); |
|
44 |
28 grabGesture(Qt::TapGesture); |
45 grabGesture(Qt::TapGesture); |
29 HbEffect::add(this, "groupbox_icon_click", "iconclick"); |
46 HbEffect::add(this, "groupbox_icon_click", "iconclick"); |
|
47 |
|
48 //shadow effect |
|
49 QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(this); |
|
50 effect->setColor(QColor(0, 0, 0, 150)); |
|
51 effect->setBlurRadius(5); |
|
52 effect->setOffset(3); |
|
53 setGraphicsEffect(effect); |
30 } |
54 } |
31 |
55 |
32 CntImageLabel::~CntImageLabel() |
56 CntImageLabel::~CntImageLabel() |
33 { |
57 { |
34 |
58 |
|
59 } |
|
60 |
|
61 void CntImageLabel::setIcon(const QPixmap &pixmap) |
|
62 { |
|
63 mPixmap = pixmap; |
|
64 |
|
65 if (!mPixmap.isNull()) |
|
66 { |
|
67 mDefaultAvatar->setVisible(false); |
|
68 mDefaultAvatar->setIcon(HbIcon()); |
|
69 } |
|
70 else |
|
71 { |
|
72 mDefaultAvatar->setIconName(QLatin1String("qtg_large_add_contact_picture")); |
|
73 mDefaultAvatar->setVisible(true); |
|
74 } |
|
75 |
|
76 update(); |
|
77 } |
|
78 |
|
79 void CntImageLabel::setAvatarIcon(const HbIcon &icon) |
|
80 { |
|
81 mIcon = icon; |
|
82 |
|
83 if (mIcon.isNull()) |
|
84 { |
|
85 mDefaultAvatar->setVisible(false); |
|
86 mDefaultAvatar->setIcon(HbIcon()); |
|
87 } |
|
88 else |
|
89 { |
|
90 mDefaultAvatar->setIcon(icon); |
|
91 mDefaultAvatar->setVisible(true); |
|
92 } |
|
93 } |
|
94 |
|
95 HbIcon CntImageLabel::avatarIcon() const |
|
96 { |
|
97 return mIcon; |
|
98 } |
|
99 |
|
100 void CntImageLabel::clear() |
|
101 { |
|
102 mIcon.clear(); |
|
103 mPixmap = NULL; |
|
104 mDefaultAvatar->setIconName(QLatin1String("qtg_large_add_contact_picture")); |
|
105 mDefaultAvatar->setVisible(true); |
|
106 } |
|
107 |
|
108 void CntImageLabel::paint(QPainter* painter, |
|
109 const QStyleOptionGraphicsItem* option, |
|
110 QWidget* widget) |
|
111 { |
|
112 Q_UNUSED(option); |
|
113 Q_UNUSED(widget); |
|
114 |
|
115 if (mPixmap.isNull()) |
|
116 { |
|
117 return; |
|
118 } |
|
119 else |
|
120 { |
|
121 painter->save(); |
|
122 QPainterPath clip; |
|
123 qreal rounding = ImageRounding * HbDeviceProfile::profile(this).unitValue(); |
|
124 clip.addRoundRect(rect(), rounding, rounding); |
|
125 painter->setClipPath(clip); |
|
126 painter->drawPixmap(rect().toRect(), mPixmap); |
|
127 painter->restore(); |
|
128 } |
35 } |
129 } |
36 |
130 |
37 void CntImageLabel::gestureEvent(QGestureEvent* event) |
131 void CntImageLabel::gestureEvent(QGestureEvent* event) |
38 { |
132 { |
39 if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) |
133 if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) |