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 <QGraphicsSceneMouseEvent> |
25 #include <hbeffect.h> |
|
26 #include <hbdeviceprofile.h> |
|
27 #include <hbiconitem.h> |
|
28 #include <hbicon.h> |
|
29 #include <hbstyle.h> |
23 |
30 |
|
31 static const qreal ImageRounding = 1.5; // units |
|
32 |
|
33 /* |
|
34 * Imagel label for landscape views. |
|
35 */ |
24 CntImageLabel::CntImageLabel(QGraphicsItem *parent) : |
36 CntImageLabel::CntImageLabel(QGraphicsItem *parent) : |
25 HbLabel(parent) |
37 HbWidget(parent) |
26 { |
38 { |
|
39 setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
40 |
|
41 mDefaultAvatar = new HbIconItem(this); |
|
42 style()->setItemName(mDefaultAvatar, "icon"); |
|
43 mDefaultAvatar->setAlignment(Qt::AlignCenter); |
|
44 |
27 grabGesture(Qt::TapGesture); |
45 grabGesture(Qt::TapGesture); |
|
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); |
28 } |
54 } |
29 |
55 |
30 CntImageLabel::~CntImageLabel() |
56 CntImageLabel::~CntImageLabel() |
31 { |
57 { |
32 |
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 } |
33 } |
129 } |
34 |
130 |
35 void CntImageLabel::gestureEvent(QGestureEvent* event) |
131 void CntImageLabel::gestureEvent(QGestureEvent* event) |
36 { |
132 { |
37 if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) |
133 if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) |
38 { |
134 { |
39 switch (tap->state()) |
135 switch (tap->state()) |
40 { |
136 { |
|
137 case Qt::GestureStarted: |
|
138 HbEffect::start(this, QString("iconclick")); |
|
139 break; |
41 case Qt::GestureFinished: |
140 case Qt::GestureFinished: |
42 if (tap->tapStyleHint() == HbTapGesture::Tap) |
141 if (tap->tapStyleHint() == HbTapGesture::Tap) |
43 { |
142 { |
44 HbInstantFeedback::play(HbFeedback::Basic); |
143 HbInstantFeedback::play(HbFeedback::Basic); |
45 emit iconClicked(); |
144 emit iconClicked(); |
46 } |
145 } |
47 break; |
146 break; |
48 case Qt::GestureUpdated: |
147 case Qt::GestureUpdated: |
49 if (tap->tapStyleHint() == HbTapGesture::TapAndHold) |
148 if (tap->tapStyleHint() == HbTapGesture::TapAndHold) |
50 { |
149 { |
|
150 HbEffect::cancel(this, QString("iconclick")); |
51 emit iconLongPressed(tap->scenePosition()); |
151 emit iconLongPressed(tap->scenePosition()); |
52 } |
152 } |
53 break; |
153 break; |
54 default: |
154 default: |
55 break; |
155 break; |
56 } |
156 } |
57 event->accept(); |
157 event->accept(); |