|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This widget displays the pixmap content. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "msgunieditorpixmapwidget.h" |
|
19 |
|
20 // SYSTEM INCLUDES |
|
21 #include <HbTapGesture> |
|
22 #include <HbWidget> |
|
23 #include <HbInstantFeedback> |
|
24 #include <HbMenu> |
|
25 #include <QPixmap> |
|
26 #include <QTimer> |
|
27 |
|
28 // USER INCLUDES |
|
29 #include "msgunieditorutils.h" |
|
30 |
|
31 // LOCAL CONSTANTS |
|
32 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
33 #define LOC_REMOVE hbTrId("txt_common_menu_remove") |
|
34 #define LOC_DETAILS hbTrId("txt_common_menu_details") |
|
35 |
|
36 const QString IMAGE_MIMETYPE("image"); |
|
37 |
|
38 //--------------------------------------------------------------- |
|
39 // MsgUnifiedEditorPixmapWidget::MsgUnifiedEditorPixmapWidget |
|
40 // @see header file |
|
41 //--------------------------------------------------------------- |
|
42 MsgUnifiedEditorPixmapWidget::MsgUnifiedEditorPixmapWidget(QGraphicsItem *parent) : |
|
43 HbIconItem(parent), |
|
44 mEditorUtils(0) |
|
45 { |
|
46 this->grabGesture(Qt::TapGesture); |
|
47 } |
|
48 |
|
49 //--------------------------------------------------------------- |
|
50 // MsgUnifiedEditorPixmapWidget::~MsgUnifiedEditorPixmapWidget |
|
51 // @see header file |
|
52 //--------------------------------------------------------------- |
|
53 MsgUnifiedEditorPixmapWidget::~MsgUnifiedEditorPixmapWidget() |
|
54 { |
|
55 } |
|
56 |
|
57 //--------------------------------------------------------------- |
|
58 // MsgUnifiedEditorPixmapWidget::setPixmap |
|
59 // @see header file |
|
60 //--------------------------------------------------------------- |
|
61 void MsgUnifiedEditorPixmapWidget::populate(const QString &pixmapPath) |
|
62 { |
|
63 mPixmapPath = pixmapPath; |
|
64 QPixmap pixmap(mPixmapPath); |
|
65 this->setIcon(HbIcon(pixmap)); |
|
66 } |
|
67 |
|
68 //--------------------------------------------------------------- |
|
69 // MsgUnifiedEditorPixmapWidget::gestureEvent |
|
70 // @see header file |
|
71 //--------------------------------------------------------------- |
|
72 void MsgUnifiedEditorPixmapWidget::gestureEvent(QGestureEvent *event) |
|
73 { |
|
74 HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture)); |
|
75 if (tapGesture) { |
|
76 switch (tapGesture->state()) { |
|
77 case Qt::GestureStarted: |
|
78 { |
|
79 // Trigger haptic feedback. |
|
80 HbInstantFeedback::play(HbFeedback::Basic); |
|
81 break; |
|
82 } |
|
83 case Qt::GestureUpdated: |
|
84 { |
|
85 if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) { |
|
86 // Handle longtap. |
|
87 handleLongTap(tapGesture->scenePosition()); |
|
88 } |
|
89 break; |
|
90 } |
|
91 case Qt::GestureFinished: |
|
92 { |
|
93 HbInstantFeedback::play(HbFeedback::Basic); |
|
94 if (HbTapGesture::Tap == tapGesture->tapStyleHint()) { |
|
95 // Handle short tap |
|
96 handleShortTap(); |
|
97 } |
|
98 break; |
|
99 } |
|
100 case Qt::GestureCanceled: |
|
101 { |
|
102 HbInstantFeedback::play(HbFeedback::Basic); |
|
103 break; |
|
104 } |
|
105 } |
|
106 } |
|
107 else { |
|
108 HbIconItem::gestureEvent(event); |
|
109 } |
|
110 } |
|
111 |
|
112 //--------------------------------------------------------------- |
|
113 // MsgUnifiedEditorPixmapWidget::handleOpen |
|
114 // @see header file |
|
115 //--------------------------------------------------------------- |
|
116 void MsgUnifiedEditorPixmapWidget::handleOpen() |
|
117 { |
|
118 this->ungrabGesture(Qt::TapGesture); |
|
119 |
|
120 if (!mEditorUtils) { |
|
121 mEditorUtils = new MsgUnifiedEditorUtils(this); |
|
122 } |
|
123 mEditorUtils->launchContentViewer(IMAGE_MIMETYPE, mPixmapPath); |
|
124 |
|
125 //fire timer to regrab gesture after some delay. |
|
126 QTimer::singleShot(300,this,SLOT(regrabGesture())); |
|
127 } |
|
128 |
|
129 //--------------------------------------------------------------- |
|
130 // MsgUnifiedEditorPixmapWidget::handleSave |
|
131 // @see header file |
|
132 //--------------------------------------------------------------- |
|
133 void MsgUnifiedEditorPixmapWidget::handleRemove() |
|
134 { |
|
135 emit remove(); |
|
136 } |
|
137 |
|
138 //--------------------------------------------------------------- |
|
139 // MsgUnifiedEditorPixmapWidget::handleSave |
|
140 // @see header file |
|
141 //--------------------------------------------------------------- |
|
142 void MsgUnifiedEditorPixmapWidget::viewDetails() |
|
143 { |
|
144 |
|
145 } |
|
146 |
|
147 //---------------------------------------------------------------------------- |
|
148 // MsgUnifiedEditorPixmapWidget::handleShortTap |
|
149 // @see header file |
|
150 //---------------------------------------------------------------------------- |
|
151 void MsgUnifiedEditorPixmapWidget::handleShortTap() |
|
152 { |
|
153 emit shortTap(mPixmapPath); |
|
154 |
|
155 // Open the media. |
|
156 handleOpen(); |
|
157 } |
|
158 |
|
159 //--------------------------------------------------------------- |
|
160 // MsgUnifiedEditorPixmapWidget::handleLongTap |
|
161 // @see header file |
|
162 //--------------------------------------------------------------- |
|
163 void MsgUnifiedEditorPixmapWidget::handleLongTap(const QPointF &position) |
|
164 { |
|
165 emit longTap(position); |
|
166 |
|
167 HbMenu* menu = new HbMenu; |
|
168 menu->setAttribute(Qt::WA_DeleteOnClose); |
|
169 menu->setDismissPolicy(HbPopup::TapAnywhere); |
|
170 |
|
171 menu->addAction(LOC_OPEN, this, SLOT(handleOpen())); |
|
172 menu->addAction(LOC_REMOVE, this, SLOT(handleRemove())); |
|
173 menu->addAction(LOC_DETAILS, this, SLOT(viewDetails())); |
|
174 |
|
175 menu->setPreferredPos(position); |
|
176 menu->show(); |
|
177 } |
|
178 |
|
179 //--------------------------------------------------------------- |
|
180 // MsgUnifiedEditorPixmapWidget::regrabGesture |
|
181 // @see header file |
|
182 //--------------------------------------------------------------- |
|
183 void MsgUnifiedEditorPixmapWidget::regrabGesture() |
|
184 { |
|
185 this->grabGesture(Qt::TapGesture); |
|
186 } |
|
187 // EOF |