22 #include <HbWidget> |
22 #include <HbWidget> |
23 #include <HbInstantFeedback> |
23 #include <HbInstantFeedback> |
24 #include <HbMenu> |
24 #include <HbMenu> |
25 #include <QPixmap> |
25 #include <QPixmap> |
26 #include <QTimer> |
26 #include <QTimer> |
|
27 #include <thumbnailmanager_qt.h> |
27 |
28 |
28 // USER INCLUDES |
29 // USER INCLUDES |
29 #include "univiewerutils.h" |
30 #include "univiewerutils.h" |
|
31 #include "unidatamodelplugininterface.h" |
30 |
32 |
31 // LOCAL CONSTANTS |
33 // LOCAL CONSTANTS |
32 #define LOC_OPEN hbTrId("txt_common_menu_open") |
34 #define LOC_OPEN hbTrId("txt_common_menu_open") |
33 #define LOC_SAVE hbTrId("txt_common_menu_save") |
35 #define LOC_SAVE hbTrId("txt_common_menu_save") |
34 |
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_large_video_player"); |
|
41 |
35 //--------------------------------------------------------------- |
42 //--------------------------------------------------------------- |
36 // UniViewerPixmapWidget::UniViewerPixmapWidget |
43 // UniViewerPixmapWidget::UniViewerPixmapWidget |
37 // @see header file |
44 // @see header file |
38 //--------------------------------------------------------------- |
45 //--------------------------------------------------------------- |
39 UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) : |
46 UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) : |
40 HbIconItem(parent), mViewerUtils(0) |
47 HbIconItem(parent), mViewerUtils(0), mThumbnailManager(0) |
41 { |
48 { |
42 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 |
43 } |
67 } |
44 |
68 |
45 //--------------------------------------------------------------- |
69 //--------------------------------------------------------------- |
46 // UniViewerPixmapWidget::~UniViewerPixmapWidget |
70 // UniViewerPixmapWidget::~UniViewerPixmapWidget |
47 // @see header file |
71 // @see header file |
52 |
76 |
53 //--------------------------------------------------------------- |
77 //--------------------------------------------------------------- |
54 // UniViewerPixmapWidget::setPixmap |
78 // UniViewerPixmapWidget::setPixmap |
55 // @see header file |
79 // @see header file |
56 //--------------------------------------------------------------- |
80 //--------------------------------------------------------------- |
57 void UniViewerPixmapWidget::populate(const QString &mimeType, const QString &pixmapPath) |
81 void UniViewerPixmapWidget::populate(UniMessageInfo *info) |
58 { |
82 { |
59 mMimeType = mimeType; |
83 mMimeType = info->mimetype(); |
60 mPixmapPath = pixmapPath; |
84 mPixmapPath = info->path(); |
61 QPixmap pixmap(mPixmapPath); |
85 if (mMimeType.contains(VIDEO_MIMETYPE)) { |
62 this->setIcon(HbIcon(pixmap)); |
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 } |
63 } |
100 } |
64 |
101 |
65 //--------------------------------------------------------------- |
102 //--------------------------------------------------------------- |
66 // UniViewerPixmapWidget::gestureEvent |
103 // UniViewerPixmapWidget::gestureEvent |
67 // @see header file |
104 // @see header file |
111 // @see header file |
148 // @see header file |
112 //--------------------------------------------------------------- |
149 //--------------------------------------------------------------- |
113 void UniViewerPixmapWidget::handleOpen() |
150 void UniViewerPixmapWidget::handleOpen() |
114 { |
151 { |
115 this->ungrabGesture(Qt::TapGesture); |
152 this->ungrabGesture(Qt::TapGesture); |
116 |
153 |
117 if (!mViewerUtils) { |
154 if (!mViewerUtils) { |
118 mViewerUtils = new UniViewerUtils(this); |
155 mViewerUtils = new UniViewerUtils(this); |
119 } |
156 } |
120 mViewerUtils->launchContentViewer(mMimeType, mPixmapPath); |
157 mViewerUtils->launchContentViewer(mMimeType, mPixmapPath); |
121 |
158 |
122 //fire timer to regrab gesture after some delay. |
159 //fire timer to regrab gesture after some delay. |
123 QTimer::singleShot(300,this,SLOT(regrabGesture())); |
160 QTimer::singleShot(300,this,SLOT(regrabGesture())); |
124 } |
161 } |
125 |
162 |
126 //--------------------------------------------------------------- |
163 //--------------------------------------------------------------- |
165 //--------------------------------------------------------------- |
202 //--------------------------------------------------------------- |
166 void UniViewerPixmapWidget::regrabGesture() |
203 void UniViewerPixmapWidget::regrabGesture() |
167 { |
204 { |
168 this->grabGesture(Qt::TapGesture); |
205 this->grabGesture(Qt::TapGesture); |
169 } |
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 // calling the sizeint forcefully as thumbnailReady is a async call |
|
221 // by the time this call has come sizeint would have already been calculated. |
|
222 this->parentWidget()->resize(-1, -1); |
|
223 } |
|
224 } |
170 // EOF |
225 // EOF |