|
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: Widget for displaying attachment media objects. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "univiewerattachmentwidget.h" |
|
19 |
|
20 // SYSTEM INCLUDES |
|
21 #include <HbIconItem> |
|
22 #include <HbTextItem> |
|
23 #include <HbFrameItem> |
|
24 #include <HbMenu> |
|
25 #include <HbEffect> |
|
26 #include <HbTapGesture> |
|
27 #include <HbInstantFeedback> |
|
28 |
|
29 #include <QFileInfo> |
|
30 #include <QTimer> |
|
31 |
|
32 // USER INCLUDES |
|
33 #include "univiewerutils.h" |
|
34 |
|
35 // LOCAL CONSTANTS |
|
36 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
37 #define LOC_SAVE hbTrId("txt_common_menu_save") |
|
38 #define LOC_SAVE_TO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts") |
|
39 |
|
40 const QString BG_FRAME_NORMAL("qtg_fr_list_normal"); |
|
41 const QString BG_FRAME_PRESSED("qtg_fr_list_pressed"); |
|
42 const QString ATTACHMENT_ICON("qtg_small_attachment"); |
|
43 const QString VCARD_MIMETYPE("text/X-vCard"); |
|
44 |
|
45 const int KILOBYTE = 1024; |
|
46 |
|
47 //---------------------------------------------------------------------------- |
|
48 // UniViewerAttachmentWidget::UniViewerAttachmentWidget |
|
49 // @see header file |
|
50 //---------------------------------------------------------------------------- |
|
51 UniViewerAttachmentWidget::UniViewerAttachmentWidget(QGraphicsItem *parent) : |
|
52 HbWidget(parent), mMediaIcon(0), mName(0), mInfo(0), mFrameItem(0), mViewerUtils(0) |
|
53 { |
|
54 this->grabGesture(Qt::TapGesture); |
|
55 |
|
56 setProperty("state", "normal"); |
|
57 |
|
58 mMediaIcon = new HbIconItem(this); |
|
59 HbStyle::setItemName(mMediaIcon, "mediaIcon"); |
|
60 |
|
61 mName = new HbTextItem(this); |
|
62 HbStyle::setItemName(mName, "text-1"); |
|
63 |
|
64 mInfo = new HbTextItem(this); |
|
65 HbStyle::setItemName(mInfo, "text-2"); |
|
66 |
|
67 mFrameItem = new HbFrameItem(BG_FRAME_NORMAL, HbFrameDrawer::NinePieces, this); |
|
68 HbStyle::setItemName(mFrameItem, "bgFrame"); |
|
69 |
|
70 HbEffect::add("attachmentWidget", "listviewitem_press", "pressed"); |
|
71 HbEffect::add("attachmentWidget", "listviewitem_release", "released"); |
|
72 } |
|
73 |
|
74 //---------------------------------------------------------------------------- |
|
75 // UniViewerAttachmentWidget::~UniViewerAttachmentWidget |
|
76 // @see header file |
|
77 //---------------------------------------------------------------------------- |
|
78 UniViewerAttachmentWidget::~UniViewerAttachmentWidget() |
|
79 { |
|
80 } |
|
81 |
|
82 //---------------------------------------------------------------------------- |
|
83 // UniViewerAttachmentWidget::populate |
|
84 // @see header file |
|
85 //---------------------------------------------------------------------------- |
|
86 void UniViewerAttachmentWidget::populate(const QString &mimeType, const QString &filePath) |
|
87 { |
|
88 mMimeType = mimeType; |
|
89 mMediaPath = filePath; |
|
90 |
|
91 mMediaIcon->setIconName(ATTACHMENT_ICON); |
|
92 |
|
93 QFileInfo fileInfo(filePath); |
|
94 mName->setText(fileInfo.fileName()); |
|
95 |
|
96 QString sizeString('B'); |
|
97 int fileSize = fileInfo.size(); |
|
98 if (fileSize > KILOBYTE) { |
|
99 // Convert to Kilobytes. |
|
100 fileSize /= KILOBYTE; |
|
101 sizeString = "Kb"; |
|
102 } |
|
103 QString fileDetails = "(" + QString::number(fileSize) + sizeString + ")"; |
|
104 mInfo->setText(fileDetails); |
|
105 } |
|
106 |
|
107 //---------------------------------------------------------------------------- |
|
108 // UniViewerAttachmentWidget::resizeEvent |
|
109 // @see header file |
|
110 //---------------------------------------------------------------------------- |
|
111 void UniViewerAttachmentWidget::gestureEvent(QGestureEvent *event) |
|
112 { |
|
113 HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture)); |
|
114 if (tapGesture) { |
|
115 switch (tapGesture->state()) { |
|
116 case Qt::GestureStarted: |
|
117 { |
|
118 // Trigger haptic feedback. |
|
119 HbInstantFeedback::play(HbFeedback::Basic); |
|
120 setPressed(true); |
|
121 break; |
|
122 } |
|
123 case Qt::GestureUpdated: |
|
124 { |
|
125 if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) { |
|
126 // Handle longtap. |
|
127 setPressed(false); |
|
128 handleLongTap(tapGesture->scenePosition()); |
|
129 } |
|
130 break; |
|
131 } |
|
132 case Qt::GestureFinished: |
|
133 { |
|
134 HbInstantFeedback::play(HbFeedback::Basic); |
|
135 if (HbTapGesture::Tap == tapGesture->tapStyleHint()) { |
|
136 // Handle short tap. |
|
137 setPressed(false); |
|
138 handleShortTap(); |
|
139 } |
|
140 break; |
|
141 } |
|
142 case Qt::GestureCanceled: |
|
143 { |
|
144 HbInstantFeedback::play(HbFeedback::Basic); |
|
145 setPressed(false); |
|
146 break; |
|
147 } |
|
148 } |
|
149 } |
|
150 else { |
|
151 HbWidget::gestureEvent(event); |
|
152 } |
|
153 } |
|
154 |
|
155 //---------------------------------------------------------------------------- |
|
156 // UniViewerAttachmentWidget::handleOpen |
|
157 // @see header file |
|
158 //---------------------------------------------------------------------------- |
|
159 void UniViewerAttachmentWidget::handleOpen() |
|
160 { |
|
161 this->ungrabGesture(Qt::TapGesture); |
|
162 |
|
163 if (!mViewerUtils) { |
|
164 mViewerUtils = new UniViewerUtils(this); |
|
165 } |
|
166 mViewerUtils->launchContentViewer(mMimeType, mMediaPath); |
|
167 |
|
168 //fire timer to regrab gesture after some delay. |
|
169 QTimer::singleShot(300,this,SLOT(regrabGesture())); |
|
170 } |
|
171 |
|
172 //---------------------------------------------------------------------------- |
|
173 // UniViewerAttachmentWidget::handleSave |
|
174 // @see header file |
|
175 //---------------------------------------------------------------------------- |
|
176 void UniViewerAttachmentWidget::handleSave() |
|
177 { |
|
178 |
|
179 } |
|
180 |
|
181 //---------------------------------------------------------------------------- |
|
182 // UniViewerAttachmentWidget::handleShortTap |
|
183 // @see header file |
|
184 //---------------------------------------------------------------------------- |
|
185 void UniViewerAttachmentWidget::handleShortTap() |
|
186 { |
|
187 emit shortTap(mMediaPath); |
|
188 |
|
189 // Open the media. |
|
190 handleOpen(); |
|
191 } |
|
192 |
|
193 //---------------------------------------------------------------------------- |
|
194 // UniViewerAttachmentWidget::handleLongTap |
|
195 // @see header file |
|
196 //---------------------------------------------------------------------------- |
|
197 void UniViewerAttachmentWidget::handleLongTap(const QPointF &position) |
|
198 { |
|
199 emit longTap(position); |
|
200 |
|
201 // Display context sensitive menu. |
|
202 HbMenu* menu = new HbMenu; |
|
203 menu->setAttribute(Qt::WA_DeleteOnClose); |
|
204 menu->setPreferredPos(position); |
|
205 |
|
206 if (mMimeType.contains(VCARD_MIMETYPE, Qt::CaseInsensitive)) { |
|
207 // For vcard opening & saving is same. |
|
208 menu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(handleOpen())); |
|
209 } |
|
210 else { |
|
211 menu->addAction(LOC_OPEN, this, SLOT(handleOpen())); |
|
212 menu->addAction(LOC_SAVE, this, SLOT(handleSave())); |
|
213 } |
|
214 |
|
215 menu->show(); |
|
216 } |
|
217 |
|
218 //---------------------------------------------------------------------------- |
|
219 // UniViewerAttachmentWidget::setPressed |
|
220 // @see header file |
|
221 //---------------------------------------------------------------------------- |
|
222 void UniViewerAttachmentWidget::setPressed(bool pressed) |
|
223 { |
|
224 if (pressed) { |
|
225 setProperty("state", "pressed"); |
|
226 mFrameItem->frameDrawer().setFrameGraphicsName(BG_FRAME_PRESSED); |
|
227 HbEffect::cancel(mFrameItem, "released"); |
|
228 HbEffect::start(mFrameItem, "attachmentWidget", "pressed"); |
|
229 |
|
230 } |
|
231 else { |
|
232 setProperty("state", "normal"); |
|
233 mFrameItem->frameDrawer().setFrameGraphicsName(BG_FRAME_NORMAL); |
|
234 HbEffect::cancel(mFrameItem, "pressed"); |
|
235 HbEffect::start(mFrameItem, "attachmentWidget", "released"); |
|
236 } |
|
237 } |
|
238 |
|
239 //--------------------------------------------------------------- |
|
240 // UniViewerAttachmentWidget::regrabGesture |
|
241 // @see header file |
|
242 //--------------------------------------------------------------- |
|
243 void UniViewerAttachmentWidget::regrabGesture() |
|
244 { |
|
245 this->grabGesture(Qt::TapGesture); |
|
246 } |
|
247 // EOF |