15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "univiewerpixmapwidget.h" |
18 #include "univiewerpixmapwidget.h" |
19 |
19 |
|
20 // SYSTEM INCLUDES |
20 #include <HbTapGesture> |
21 #include <HbTapGesture> |
21 #include <HbWidget> |
22 #include <HbWidget> |
22 #include <HbInstantFeedback> |
23 #include <HbInstantFeedback> |
|
24 #include <HbMenu> |
23 #include <QPixmap> |
25 #include <QPixmap> |
|
26 #include <QTimer> |
|
27 #include <thumbnailmanager_qt.h> |
|
28 |
|
29 // USER INCLUDES |
|
30 #include "univiewerutils.h" |
|
31 #include "unidatamodelplugininterface.h" |
|
32 |
|
33 // LOCAL CONSTANTS |
|
34 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
35 #define LOC_SAVE hbTrId("txt_common_menu_save") |
|
36 |
|
37 const QString PIXMAP_ICON("qtg_small_image"); |
|
38 const QString CORRUPTED_PIXMAP_ICON("qtg_large_corrupted"); |
|
39 const QString VIDEO_MIMETYPE("video"); |
|
40 const QString MSG_VIDEO_ICON("qtg_small_video"); |
24 |
41 |
25 //--------------------------------------------------------------- |
42 //--------------------------------------------------------------- |
26 // UniViewerPixmapWidget::UniViewerPixmapWidget |
43 // UniViewerPixmapWidget::UniViewerPixmapWidget |
27 // @see header file |
44 // @see header file |
28 //--------------------------------------------------------------- |
45 //--------------------------------------------------------------- |
29 UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) : |
46 UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) : |
30 HbIconItem(parent) |
47 HbIconItem(parent), mViewerUtils(0), mThumbnailManager(0) |
31 { |
48 { |
32 mPixmapFile = QString(""); |
|
33 this->grabGesture(Qt::TapGesture); |
49 this->grabGesture(Qt::TapGesture); |
|
50 init(); |
|
51 } |
|
52 |
|
53 //--------------------------------------------------------------- |
|
54 // UniViewerPixmapWidget::init |
|
55 // @see header file |
|
56 //--------------------------------------------------------------- |
|
57 void UniViewerPixmapWidget::init() |
|
58 { |
|
59 mThumbnailManager = new ThumbnailManager(this); |
|
60 mThumbnailManager->setMode(ThumbnailManager::Default); |
|
61 mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality); |
|
62 mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge); |
|
63 |
|
64 connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), this, |
|
65 SLOT(thumbnailReady(QPixmap, void*, int, int))); |
|
66 |
34 } |
67 } |
35 |
68 |
36 //--------------------------------------------------------------- |
69 //--------------------------------------------------------------- |
37 // UniViewerPixmapWidget::~UniViewerPixmapWidget |
70 // UniViewerPixmapWidget::~UniViewerPixmapWidget |
38 // @see header file |
71 // @see header file |
43 |
76 |
44 //--------------------------------------------------------------- |
77 //--------------------------------------------------------------- |
45 // UniViewerPixmapWidget::setPixmap |
78 // UniViewerPixmapWidget::setPixmap |
46 // @see header file |
79 // @see header file |
47 //--------------------------------------------------------------- |
80 //--------------------------------------------------------------- |
48 void UniViewerPixmapWidget::setPixmap(const QString &pixmapPath) |
81 void UniViewerPixmapWidget::populate(UniMessageInfo *info) |
49 { |
82 { |
50 mPixmapFile = pixmapPath; |
83 mMimeType = info->mimetype(); |
51 QPixmap pixmap(pixmapPath); |
84 mPixmapPath = info->path(); |
52 this->setIcon(HbIcon(pixmap)); |
85 if (mMimeType.contains(VIDEO_MIMETYPE)) { |
|
86 this->setIcon(MSG_VIDEO_ICON); |
|
87 mThumbnailManager->getThumbnail(mPixmapPath); |
|
88 this->ungrabGesture(Qt::TapGesture); |
|
89 } |
|
90 else if (info->isProtected()) { |
|
91 this->setIconName(PIXMAP_ICON); |
|
92 } |
|
93 else if (info->isCorrupted()) { |
|
94 this->setIconName(CORRUPTED_PIXMAP_ICON); |
|
95 } |
|
96 else { |
|
97 QPixmap pixmap(mPixmapPath); |
|
98 this->setIcon(HbIcon(pixmap)); |
|
99 } |
53 } |
100 } |
54 |
101 |
55 //--------------------------------------------------------------- |
102 //--------------------------------------------------------------- |
56 // UniViewerPixmapWidget::gestureEvent |
103 // UniViewerPixmapWidget::gestureEvent |
57 // @see header file |
104 // @see header file |
68 break; |
115 break; |
69 } |
116 } |
70 case Qt::GestureUpdated: |
117 case Qt::GestureUpdated: |
71 { |
118 { |
72 if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) { |
119 if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) { |
73 // emit longtap |
120 // Handle longtap. |
|
121 handleLongTap(tapGesture->scenePosition()); |
74 } |
122 } |
75 break; |
123 break; |
76 } |
124 } |
77 case Qt::GestureFinished: |
125 case Qt::GestureFinished: |
78 { |
126 { |
|
127 HbInstantFeedback::play(HbFeedback::Basic); |
79 if (HbTapGesture::Tap == tapGesture->tapStyleHint()) { |
128 if (HbTapGesture::Tap == tapGesture->tapStyleHint()) { |
80 // Emit short tap |
129 // Handle short tap |
81 emit shortTap(mPixmapFile); |
130 handleShortTap(); |
82 } |
131 } |
83 break; |
132 break; |
84 } |
133 } |
85 case Qt::GestureCanceled: |
134 case Qt::GestureCanceled: |
86 { |
135 { |
87 break; |
136 HbInstantFeedback::play(HbFeedback::Basic); |
88 } |
137 break; |
89 } |
138 } |
90 } |
139 } |
91 } |
140 } |
92 |
141 else { |
|
142 HbIconItem::gestureEvent(event); |
|
143 } |
|
144 } |
|
145 |
|
146 //--------------------------------------------------------------- |
|
147 // UniViewerPixmapWidget::handleOpen |
|
148 // @see header file |
|
149 //--------------------------------------------------------------- |
|
150 void UniViewerPixmapWidget::handleOpen() |
|
151 { |
|
152 this->ungrabGesture(Qt::TapGesture); |
|
153 |
|
154 if (!mViewerUtils) { |
|
155 mViewerUtils = new UniViewerUtils(this); |
|
156 } |
|
157 mViewerUtils->launchContentViewer(mMimeType, mPixmapPath); |
|
158 |
|
159 //fire timer to regrab gesture after some delay. |
|
160 QTimer::singleShot(300,this,SLOT(regrabGesture())); |
|
161 } |
|
162 |
|
163 //--------------------------------------------------------------- |
|
164 // UniViewerPixmapWidget::handleSave |
|
165 // @see header file |
|
166 //--------------------------------------------------------------- |
|
167 void UniViewerPixmapWidget::handleSave() |
|
168 { |
|
169 } |
|
170 |
|
171 //---------------------------------------------------------------------------- |
|
172 // UniViewerPixmapWidget::handleShortTap |
|
173 // @see header file |
|
174 //---------------------------------------------------------------------------- |
|
175 void UniViewerPixmapWidget::handleShortTap() |
|
176 { |
|
177 emit shortTap(mPixmapPath); |
|
178 |
|
179 // Open the media. |
|
180 handleOpen(); |
|
181 } |
|
182 |
|
183 //--------------------------------------------------------------- |
|
184 // UniViewerPixmapWidget::handleLongTap |
|
185 // @see header file |
|
186 //--------------------------------------------------------------- |
|
187 void UniViewerPixmapWidget::handleLongTap(const QPointF &position) |
|
188 { |
|
189 emit longTap(position); |
|
190 |
|
191 HbMenu* menu = new HbMenu; |
|
192 menu->setAttribute(Qt::WA_DeleteOnClose); |
|
193 menu->addAction(LOC_OPEN, this, SLOT(handleOpen())); |
|
194 menu->addAction(LOC_SAVE, this, SLOT(handleSave())); |
|
195 menu->setPreferredPos(position); |
|
196 menu->show(); |
|
197 } |
|
198 |
|
199 //--------------------------------------------------------------- |
|
200 // UniViewerPixmapWidget::regrabGesture |
|
201 // @see header file |
|
202 //--------------------------------------------------------------- |
|
203 void UniViewerPixmapWidget::regrabGesture() |
|
204 { |
|
205 this->grabGesture(Qt::TapGesture); |
|
206 } |
|
207 |
|
208 //--------------------------------------------------------------- |
|
209 // UniViewerPixmapWidget::thumbnailReady |
|
210 // @see header |
|
211 //--------------------------------------------------------------- |
|
212 void UniViewerPixmapWidget::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error) |
|
213 { |
|
214 Q_UNUSED(data) |
|
215 Q_UNUSED(id) |
|
216 this->grabGesture(Qt::TapGesture); |
|
217 if (!error) { |
|
218 this->setIcon(HbIcon(pixmap)); |
|
219 this->hide(); |
|
220 this->updateGeometry(); |
|
221 } |
|
222 } |
93 // EOF |
223 // EOF |