37
|
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 in viewer.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "univiewerpixmapwidget.h"
|
|
19 |
|
|
20 |
// SYSTEM INCLUDES
|
|
21 |
#include <HbTapGesture>
|
|
22 |
#include <HbWidget>
|
|
23 |
#include <HbInstantFeedback>
|
|
24 |
#include <HbMenu>
|
|
25 |
#include <QPixmap>
|
|
26 |
#include <QTimer>
|
|
27 |
#include <thumbnailmanager_qt.h>
|
|
28 |
|
|
29 |
// USER INCLUDES
|
73
|
30 |
#include "msgservicelaunchutil.h"
|
37
|
31 |
#include "unidatamodelplugininterface.h"
|
|
32 |
|
|
33 |
// LOCAL CONSTANTS
|
|
34 |
#define LOC_OPEN hbTrId("txt_common_menu_open")
|
62
|
35 |
|
37
|
36 |
|
51
|
37 |
static const char PIXMAP_ICON[] = "qtg_small_image";
|
|
38 |
static const char CORRUPTED_PIXMAP_ICON[] = "qtg_large_corrupted";
|
|
39 |
static const char VIDEO_MIMETYPE[] = "video";
|
41
|
40 |
|
51
|
41 |
static const int WIDTH_RATIO = 4;
|
|
42 |
static const int HEIGHT_RATIO = 3;
|
37
|
43 |
|
|
44 |
//---------------------------------------------------------------
|
|
45 |
// UniViewerPixmapWidget::UniViewerPixmapWidget
|
|
46 |
// @see header file
|
|
47 |
//---------------------------------------------------------------
|
|
48 |
UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) :
|
51
|
49 |
HbIconItem(parent), mInfo(0), mViewerUtils(0), mThumbnailManager(0)
|
37
|
50 |
{
|
|
51 |
this->grabGesture(Qt::TapGesture);
|
|
52 |
init();
|
|
53 |
}
|
|
54 |
|
|
55 |
//---------------------------------------------------------------
|
|
56 |
// UniViewerPixmapWidget::~UniViewerPixmapWidget
|
|
57 |
// @see header file
|
|
58 |
//---------------------------------------------------------------
|
|
59 |
UniViewerPixmapWidget::~UniViewerPixmapWidget()
|
|
60 |
{
|
51
|
61 |
if (mInfo) {
|
|
62 |
delete mInfo;
|
|
63 |
mInfo = NULL;
|
|
64 |
}
|
37
|
65 |
}
|
|
66 |
|
|
67 |
//---------------------------------------------------------------
|
51
|
68 |
// UniViewerPixmapWidget::populate
|
37
|
69 |
// @see header file
|
|
70 |
//---------------------------------------------------------------
|
|
71 |
void UniViewerPixmapWidget::populate(UniMessageInfo *info)
|
|
72 |
{
|
|
73 |
mMimeType = info->mimetype();
|
|
74 |
mPixmapPath = info->path();
|
51
|
75 |
|
|
76 |
/**
|
|
77 |
* Create a copy of info for video content.
|
|
78 |
* mInfo will be deleted in the destructor.
|
|
79 |
*/
|
37
|
80 |
if (mMimeType.contains(VIDEO_MIMETYPE)) {
|
51
|
81 |
mInfo = new UniMessageInfo(*info);
|
37
|
82 |
}
|
51
|
83 |
|
|
84 |
if (info->isProtected()) {
|
|
85 |
if (mMimeType.contains(VIDEO_MIMETYPE)) {
|
|
86 |
emit thumbnailFound(false, mInfo);
|
|
87 |
}
|
|
88 |
else {
|
|
89 |
this->setIconName(PIXMAP_ICON);
|
|
90 |
}
|
37
|
91 |
}
|
|
92 |
else if (info->isCorrupted()) {
|
51
|
93 |
if (mMimeType.contains(VIDEO_MIMETYPE)) {
|
|
94 |
emit thumbnailFound(false, mInfo);
|
|
95 |
}
|
|
96 |
else {
|
|
97 |
this->setIconName(CORRUPTED_PIXMAP_ICON);
|
|
98 |
}
|
37
|
99 |
}
|
|
100 |
else {
|
51
|
101 |
if (mMimeType.contains(VIDEO_MIMETYPE)) {
|
|
102 |
mThumbnailManager->getThumbnail(mPixmapPath);
|
|
103 |
this->ungrabGesture(Qt::TapGesture);
|
|
104 |
}
|
|
105 |
else {
|
|
106 |
QPixmap pixmap(mPixmapPath);
|
|
107 |
this->setIcon(HbIcon(pixmap));
|
|
108 |
}
|
37
|
109 |
}
|
|
110 |
}
|
|
111 |
|
|
112 |
//---------------------------------------------------------------
|
|
113 |
// UniViewerPixmapWidget::gestureEvent
|
|
114 |
// @see header file
|
|
115 |
//---------------------------------------------------------------
|
|
116 |
void UniViewerPixmapWidget::gestureEvent(QGestureEvent *event)
|
|
117 |
{
|
|
118 |
HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture));
|
|
119 |
if (tapGesture) {
|
|
120 |
switch (tapGesture->state()) {
|
|
121 |
case Qt::GestureStarted:
|
|
122 |
{
|
|
123 |
// Trigger haptic feedback.
|
|
124 |
HbInstantFeedback::play(HbFeedback::Basic);
|
|
125 |
break;
|
|
126 |
}
|
|
127 |
case Qt::GestureUpdated:
|
|
128 |
{
|
|
129 |
if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) {
|
|
130 |
// Handle longtap.
|
|
131 |
handleLongTap(tapGesture->scenePosition());
|
|
132 |
}
|
|
133 |
break;
|
|
134 |
}
|
|
135 |
case Qt::GestureFinished:
|
|
136 |
{
|
|
137 |
HbInstantFeedback::play(HbFeedback::Basic);
|
|
138 |
if (HbTapGesture::Tap == tapGesture->tapStyleHint()) {
|
|
139 |
// Handle short tap
|
|
140 |
handleShortTap();
|
|
141 |
}
|
|
142 |
break;
|
|
143 |
}
|
|
144 |
case Qt::GestureCanceled:
|
|
145 |
{
|
|
146 |
HbInstantFeedback::play(HbFeedback::Basic);
|
|
147 |
break;
|
|
148 |
}
|
|
149 |
}
|
|
150 |
}
|
|
151 |
else {
|
|
152 |
HbIconItem::gestureEvent(event);
|
|
153 |
}
|
|
154 |
}
|
|
155 |
|
|
156 |
//---------------------------------------------------------------
|
|
157 |
// UniViewerPixmapWidget::handleOpen
|
|
158 |
// @see header file
|
|
159 |
//---------------------------------------------------------------
|
|
160 |
void UniViewerPixmapWidget::handleOpen()
|
|
161 |
{
|
|
162 |
this->ungrabGesture(Qt::TapGesture);
|
|
163 |
|
|
164 |
if (!mViewerUtils) {
|
73
|
165 |
mViewerUtils = new MsgServiceLaunchUtil(this);
|
37
|
166 |
}
|
|
167 |
mViewerUtils->launchContentViewer(mMimeType, mPixmapPath);
|
|
168 |
|
|
169 |
//fire timer to regrab gesture after some delay.
|
|
170 |
QTimer::singleShot(300,this,SLOT(regrabGesture()));
|
|
171 |
}
|
|
172 |
|
73
|
173 |
|
|
174 |
|
41
|
175 |
//---------------------------------------------------------------
|
|
176 |
// UniViewerPixmapWidget::regrabGesture
|
|
177 |
// @see header file
|
|
178 |
//---------------------------------------------------------------
|
|
179 |
void UniViewerPixmapWidget::regrabGesture()
|
|
180 |
{
|
|
181 |
this->grabGesture(Qt::TapGesture);
|
|
182 |
}
|
|
183 |
|
|
184 |
//---------------------------------------------------------------
|
|
185 |
// UniViewerPixmapWidget::thumbnailReady
|
|
186 |
// @see header
|
|
187 |
//---------------------------------------------------------------
|
|
188 |
void UniViewerPixmapWidget::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
|
|
189 |
{
|
|
190 |
Q_UNUSED(data)
|
|
191 |
Q_UNUSED(id)
|
|
192 |
this->grabGesture(Qt::TapGesture);
|
51
|
193 |
if (error) {
|
|
194 |
emit thumbnailFound(false, mInfo);
|
|
195 |
}
|
|
196 |
else {
|
41
|
197 |
this->setIcon(HbIcon(pixmap));
|
|
198 |
this->hide();
|
51
|
199 |
emit thumbnailFound(true, NULL);
|
41
|
200 |
}
|
|
201 |
}
|
|
202 |
|
|
203 |
//---------------------------------------------------------------
|
|
204 |
// UniViewerPixmapWidget::init
|
|
205 |
// @see header file
|
|
206 |
//---------------------------------------------------------------
|
|
207 |
void UniViewerPixmapWidget::init()
|
|
208 |
{
|
|
209 |
mThumbnailManager = new ThumbnailManager(this);
|
|
210 |
mThumbnailManager->setMode(ThumbnailManager::CropToAspectRatio);
|
|
211 |
mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality);
|
|
212 |
mThumbnailManager->setThumbnailSize(getThumbnailSize());
|
|
213 |
|
|
214 |
connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), this,
|
|
215 |
SLOT(thumbnailReady(QPixmap, void*, int, int)));
|
|
216 |
}
|
|
217 |
|
37
|
218 |
//----------------------------------------------------------------------------
|
|
219 |
// UniViewerPixmapWidget::handleShortTap
|
|
220 |
// @see header file
|
|
221 |
//----------------------------------------------------------------------------
|
|
222 |
void UniViewerPixmapWidget::handleShortTap()
|
|
223 |
{
|
|
224 |
emit shortTap(mPixmapPath);
|
|
225 |
|
|
226 |
// Open the media.
|
|
227 |
handleOpen();
|
|
228 |
}
|
|
229 |
|
|
230 |
//---------------------------------------------------------------
|
|
231 |
// UniViewerPixmapWidget::handleLongTap
|
|
232 |
// @see header file
|
|
233 |
//---------------------------------------------------------------
|
|
234 |
void UniViewerPixmapWidget::handleLongTap(const QPointF &position)
|
|
235 |
{
|
|
236 |
emit longTap(position);
|
|
237 |
|
|
238 |
HbMenu* menu = new HbMenu;
|
|
239 |
menu->setAttribute(Qt::WA_DeleteOnClose);
|
|
240 |
menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
|
62
|
241 |
|
37
|
242 |
menu->setPreferredPos(position);
|
|
243 |
menu->show();
|
|
244 |
}
|
|
245 |
|
|
246 |
//---------------------------------------------------------------
|
41
|
247 |
// UniViewerPixmapWidget::getThumbnailSize
|
37
|
248 |
// @see header file
|
|
249 |
//---------------------------------------------------------------
|
41
|
250 |
QSize UniViewerPixmapWidget::getThumbnailSize()
|
37
|
251 |
{
|
41
|
252 |
QSize thumbnailSize(1, 1);
|
|
253 |
HbWidget *parent = qobject_cast<HbWidget *>(this->parentWidget());
|
|
254 |
|
|
255 |
if (parent) {
|
|
256 |
qreal thumbnailWidth = 0.0;
|
|
257 |
qreal thumbnailHeight = 0.0;
|
|
258 |
parent->style()->parameter("hb-param-screen-short-edge", thumbnailWidth);
|
|
259 |
thumbnailHeight = (thumbnailWidth * HEIGHT_RATIO) / WIDTH_RATIO;
|
|
260 |
thumbnailSize.setHeight(qRound(thumbnailHeight));
|
|
261 |
thumbnailSize.setWidth(qRound(thumbnailWidth));
|
|
262 |
}
|
|
263 |
return thumbnailSize;
|
37
|
264 |
}
|
|
265 |
|
|
266 |
// EOF
|