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 |
|
28 // USER INCLUDES |
|
29 #include "univiewerutils.h" |
|
30 |
|
31 // LOCAL CONSTANTS |
|
32 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
33 #define LOC_SAVE hbTrId("txt_common_menu_save") |
24 |
34 |
25 //--------------------------------------------------------------- |
35 //--------------------------------------------------------------- |
26 // UniViewerPixmapWidget::UniViewerPixmapWidget |
36 // UniViewerPixmapWidget::UniViewerPixmapWidget |
27 // @see header file |
37 // @see header file |
28 //--------------------------------------------------------------- |
38 //--------------------------------------------------------------- |
29 UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) : |
39 UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) : |
30 HbIconItem(parent) |
40 HbIconItem(parent), mViewerUtils(0) |
31 { |
41 { |
32 mPixmapFile = QString(""); |
|
33 this->grabGesture(Qt::TapGesture); |
42 this->grabGesture(Qt::TapGesture); |
34 } |
43 } |
35 |
44 |
36 //--------------------------------------------------------------- |
45 //--------------------------------------------------------------- |
37 // UniViewerPixmapWidget::~UniViewerPixmapWidget |
46 // UniViewerPixmapWidget::~UniViewerPixmapWidget |
43 |
52 |
44 //--------------------------------------------------------------- |
53 //--------------------------------------------------------------- |
45 // UniViewerPixmapWidget::setPixmap |
54 // UniViewerPixmapWidget::setPixmap |
46 // @see header file |
55 // @see header file |
47 //--------------------------------------------------------------- |
56 //--------------------------------------------------------------- |
48 void UniViewerPixmapWidget::setPixmap(const QString &pixmapPath) |
57 void UniViewerPixmapWidget::populate(const QString &mimeType, const QString &pixmapPath) |
49 { |
58 { |
50 mPixmapFile = pixmapPath; |
59 mMimeType = mimeType; |
51 QPixmap pixmap(pixmapPath); |
60 mPixmapPath = pixmapPath; |
|
61 QPixmap pixmap(mPixmapPath); |
52 this->setIcon(HbIcon(pixmap)); |
62 this->setIcon(HbIcon(pixmap)); |
53 } |
63 } |
54 |
64 |
55 //--------------------------------------------------------------- |
65 //--------------------------------------------------------------- |
56 // UniViewerPixmapWidget::gestureEvent |
66 // UniViewerPixmapWidget::gestureEvent |
68 break; |
78 break; |
69 } |
79 } |
70 case Qt::GestureUpdated: |
80 case Qt::GestureUpdated: |
71 { |
81 { |
72 if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) { |
82 if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) { |
73 // emit longtap |
83 // Handle longtap. |
|
84 handleLongTap(tapGesture->scenePosition()); |
74 } |
85 } |
75 break; |
86 break; |
76 } |
87 } |
77 case Qt::GestureFinished: |
88 case Qt::GestureFinished: |
78 { |
89 { |
|
90 HbInstantFeedback::play(HbFeedback::Basic); |
79 if (HbTapGesture::Tap == tapGesture->tapStyleHint()) { |
91 if (HbTapGesture::Tap == tapGesture->tapStyleHint()) { |
80 // Emit short tap |
92 // Handle short tap |
81 emit shortTap(mPixmapFile); |
93 handleShortTap(); |
82 } |
94 } |
83 break; |
95 break; |
84 } |
96 } |
85 case Qt::GestureCanceled: |
97 case Qt::GestureCanceled: |
86 { |
98 { |
|
99 HbInstantFeedback::play(HbFeedback::Basic); |
87 break; |
100 break; |
88 } |
101 } |
89 } |
102 } |
90 } |
103 } |
|
104 else { |
|
105 HbIconItem::gestureEvent(event); |
|
106 } |
91 } |
107 } |
92 |
108 |
|
109 //--------------------------------------------------------------- |
|
110 // UniViewerPixmapWidget::handleOpen |
|
111 // @see header file |
|
112 //--------------------------------------------------------------- |
|
113 void UniViewerPixmapWidget::handleOpen() |
|
114 { |
|
115 this->ungrabGesture(Qt::TapGesture); |
|
116 |
|
117 if (!mViewerUtils) { |
|
118 mViewerUtils = new UniViewerUtils(this); |
|
119 } |
|
120 mViewerUtils->launchContentViewer(mMimeType, mPixmapPath); |
|
121 |
|
122 //fire timer to regrab gesture after some delay. |
|
123 QTimer::singleShot(300,this,SLOT(regrabGesture())); |
|
124 } |
|
125 |
|
126 //--------------------------------------------------------------- |
|
127 // UniViewerPixmapWidget::handleSave |
|
128 // @see header file |
|
129 //--------------------------------------------------------------- |
|
130 void UniViewerPixmapWidget::handleSave() |
|
131 { |
|
132 } |
|
133 |
|
134 //---------------------------------------------------------------------------- |
|
135 // UniViewerPixmapWidget::handleShortTap |
|
136 // @see header file |
|
137 //---------------------------------------------------------------------------- |
|
138 void UniViewerPixmapWidget::handleShortTap() |
|
139 { |
|
140 emit shortTap(mPixmapPath); |
|
141 |
|
142 // Open the media. |
|
143 handleOpen(); |
|
144 } |
|
145 |
|
146 //--------------------------------------------------------------- |
|
147 // UniViewerPixmapWidget::handleLongTap |
|
148 // @see header file |
|
149 //--------------------------------------------------------------- |
|
150 void UniViewerPixmapWidget::handleLongTap(const QPointF &position) |
|
151 { |
|
152 emit longTap(position); |
|
153 |
|
154 HbMenu* menu = new HbMenu; |
|
155 menu->setAttribute(Qt::WA_DeleteOnClose); |
|
156 menu->addAction(LOC_OPEN, this, SLOT(handleOpen())); |
|
157 menu->addAction(LOC_SAVE, this, SLOT(handleSave())); |
|
158 menu->setPreferredPos(position); |
|
159 menu->show(); |
|
160 } |
|
161 |
|
162 //--------------------------------------------------------------- |
|
163 // UniViewerPixmapWidget::regrabGesture |
|
164 // @see header file |
|
165 //--------------------------------------------------------------- |
|
166 void UniViewerPixmapWidget::regrabGesture() |
|
167 { |
|
168 this->grabGesture(Qt::TapGesture); |
|
169 } |
93 // EOF |
170 // EOF |