21 static const QString FILE_PATH_CSS = ":nmattachmentlistitem.css"; |
21 static const QString FILE_PATH_CSS = ":nmattachmentlistitem.css"; |
22 |
22 |
23 static const int PROGRESSBAR_MIN = 0; |
23 static const int PROGRESSBAR_MIN = 0; |
24 static const int PROGRESSBAR_MAX = 100; |
24 static const int PROGRESSBAR_MAX = 100; |
25 static const int PROGRESSBAR_HIDE_COUNTDOWN = 500; |
25 static const int PROGRESSBAR_HIDE_COUNTDOWN = 500; |
26 static const int LONGPRESS_TIMER = 2000; |
|
27 |
26 |
28 // Hardcoded file size length. Maximum (999.9 Mb) fits into size field. |
27 // Hardcoded file size length. Maximum (999.9 Mb) fits into size field. |
29 static const int FILE_SIZE_FIELD_LENGTH = 120; |
28 static const int FILE_SIZE_FIELD_LENGTH = 120; |
30 |
29 |
31 /*! |
30 /*! |
45 */ |
44 */ |
46 NmAttachmentListItem::NmAttachmentListItem(QGraphicsItem *parent) |
45 NmAttachmentListItem::NmAttachmentListItem(QGraphicsItem *parent) |
47 : HbWidget( parent ), |
46 : HbWidget( parent ), |
48 mFileNameText(NULL), |
47 mFileNameText(NULL), |
49 mFileSizeText(NULL), |
48 mFileSizeText(NULL), |
50 mProgressBar(NULL), |
49 mProgressBar(NULL) |
51 mTimer(NULL), |
50 { |
52 mButtonPressed(false), |
51 NM_FUNCTION; |
53 mLongPressedPoint(0,0) |
52 |
54 { |
|
55 init( ); |
53 init( ); |
|
54 |
|
55 // Informs GestureFramework that NmAttachmentListItem widget is interested |
|
56 // Tap gesture and TapAndHold gesture. |
|
57 grabGesture(Qt::TapGesture); |
56 } |
58 } |
57 |
59 |
58 /*! |
60 /*! |
59 Setter for items text color override. This fucntion can be used |
61 Setter for items text color override. This fucntion can be used |
60 if theme background is not used and text needs to be shown in diferent color. |
62 if theme background is not used and text needs to be shown in diferent color. |
61 */ |
63 */ |
62 void NmAttachmentListItem::setTextColor(const QColor color) |
64 void NmAttachmentListItem::setTextColor(const QColor color) |
63 { |
65 { |
|
66 NM_FUNCTION; |
|
67 |
64 mTextColor=color; |
68 mTextColor=color; |
65 } |
69 } |
66 |
70 |
67 /*! |
71 /*! |
68 Destructor. |
72 Destructor. |
69 */ |
73 */ |
70 NmAttachmentListItem::~NmAttachmentListItem( ) |
74 NmAttachmentListItem::~NmAttachmentListItem( ) |
71 { |
75 { |
|
76 NM_FUNCTION; |
|
77 |
72 HbStyleLoader::unregisterFilePath(FILE_PATH_WIDGETML); |
78 HbStyleLoader::unregisterFilePath(FILE_PATH_WIDGETML); |
73 HbStyleLoader::unregisterFilePath(FILE_PATH_CSS); |
79 HbStyleLoader::unregisterFilePath(FILE_PATH_CSS); |
74 |
|
75 delete mTimer; |
|
76 mTimer = NULL; |
|
77 } |
80 } |
78 |
81 |
79 /*! |
82 /*! |
80 Set the text to be displayed in the file name item. |
83 Set the text to be displayed in the file name item. |
81 */ |
84 */ |
82 void NmAttachmentListItem::setFileNameText(const QString &fileName) |
85 void NmAttachmentListItem::setFileNameText(const QString &fileName) |
83 { |
86 { |
|
87 NM_FUNCTION; |
|
88 |
84 if (mFileNameText){ |
89 if (mFileNameText){ |
85 if (mTextColor.isValid()){ |
90 if (mTextColor.isValid()){ |
86 mFileNameText->setTextColor(mTextColor); |
91 mFileNameText->setTextColor(mTextColor); |
87 } |
92 } |
88 mFileNameText->setTextWrapping(Hb::TextNoWrap); |
93 mFileNameText->setTextWrapping(Hb::TextNoWrap); |
93 /*! |
98 /*! |
94 Set the text to be displayed in the file size item |
99 Set the text to be displayed in the file size item |
95 */ |
100 */ |
96 void NmAttachmentListItem::setFileSizeText(const QString &fileSize) |
101 void NmAttachmentListItem::setFileSizeText(const QString &fileSize) |
97 { |
102 { |
|
103 NM_FUNCTION; |
|
104 |
98 if (mFileSizeText){ |
105 if (mFileSizeText){ |
99 if (mTextColor.isValid()){ |
106 if (mTextColor.isValid()){ |
100 mFileSizeText->setTextColor(mTextColor); |
107 mFileSizeText->setTextColor(mTextColor); |
101 } |
108 } |
102 mFileSizeText->setTextWrapping(Hb::TextNoWrap); |
109 mFileSizeText->setTextWrapping(Hb::TextNoWrap); |
107 /*! |
114 /*! |
108 Set the length of the filename field. |
115 Set the length of the filename field. |
109 */ |
116 */ |
110 void NmAttachmentListItem::resetFileNameLength(Qt::Orientation orientation) |
117 void NmAttachmentListItem::resetFileNameLength(Qt::Orientation orientation) |
111 { |
118 { |
|
119 NM_FUNCTION; |
|
120 |
112 QSizeF reso = screenSize(orientation); |
121 QSizeF reso = screenSize(orientation); |
113 |
122 |
114 if (orientation == Qt::Horizontal) { |
123 if (orientation == Qt::Horizontal) { |
115 mFileNameText->setPreferredWidth(reso.width() / 2 - FILE_SIZE_FIELD_LENGTH); |
124 mFileNameText->setPreferredWidth(reso.width() / 2 - FILE_SIZE_FIELD_LENGTH); |
116 } |
125 } |
161 /*! |
174 /*! |
162 Hides progress bar, used if download is cancelled before 100 precent is reached |
175 Hides progress bar, used if download is cancelled before 100 precent is reached |
163 */ |
176 */ |
164 void NmAttachmentListItem::hideProgressBar() |
177 void NmAttachmentListItem::hideProgressBar() |
165 { |
178 { |
|
179 NM_FUNCTION; |
|
180 |
166 QTimer::singleShot(PROGRESSBAR_HIDE_COUNTDOWN,this, SLOT(removeProgressBar())); |
181 QTimer::singleShot(PROGRESSBAR_HIDE_COUNTDOWN,this, SLOT(removeProgressBar())); |
167 } |
182 } |
168 |
183 |
169 /*! |
184 /*! |
170 Initialize |
185 Initialize |
171 */ |
186 */ |
172 void NmAttachmentListItem::init( ) |
187 void NmAttachmentListItem::init( ) |
173 { |
188 { |
|
189 NM_FUNCTION; |
|
190 |
174 constructUi(); |
191 constructUi(); |
175 |
192 |
176 //set default values |
193 //set default values |
177 setFlag(QGraphicsItem::ItemIsFocusable); |
194 setFlag(QGraphicsItem::ItemIsFocusable); |
178 setFlag(QGraphicsItem::ItemIsSelectable); |
195 setFlag(QGraphicsItem::ItemIsSelectable); |
179 |
|
180 //set temporary longpress timer |
|
181 mTimer = new QTimer(this); |
|
182 mTimer->setSingleShot(true); |
|
183 connect(mTimer, SIGNAL(timeout()), this, SLOT(longPressedActivated())); |
|
184 } |
196 } |
185 |
197 |
186 /*! |
198 /*! |
187 Constructs the UI, sets style itemnames etc. |
199 Constructs the UI, sets style itemnames etc. |
188 */ |
200 */ |
189 void NmAttachmentListItem::constructUi() |
201 void NmAttachmentListItem::constructUi() |
190 { |
202 { |
|
203 NM_FUNCTION; |
|
204 |
191 //construct default ui. |
205 //construct default ui. |
192 HbStyleLoader::registerFilePath(FILE_PATH_WIDGETML); |
206 HbStyleLoader::registerFilePath(FILE_PATH_WIDGETML); |
193 HbStyleLoader::registerFilePath(FILE_PATH_CSS); |
207 HbStyleLoader::registerFilePath(FILE_PATH_CSS); |
194 |
208 |
195 mFileNameText = new HbTextItem(this); |
209 mFileNameText = new HbTextItem(this); |
203 mFileSizeText->setElideMode(Qt::ElideNone); |
217 mFileSizeText->setElideMode(Qt::ElideNone); |
204 } |
218 } |
205 |
219 |
206 |
220 |
207 /*! |
221 /*! |
208 \reimp |
|
209 */ |
|
210 void NmAttachmentListItem::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
|
211 { |
|
212 NMLOG("NmAttachmentListItem::mousePressEvent"); |
|
213 |
|
214 mButtonPressed = true; |
|
215 mLongPressedPoint = event->scenePos(); |
|
216 if(mTimer){ |
|
217 mTimer->start(LONGPRESS_TIMER); |
|
218 } |
|
219 } |
|
220 |
|
221 /*! |
|
222 \reimp |
|
223 */ |
|
224 void NmAttachmentListItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
225 { |
|
226 Q_UNUSED(event); |
|
227 NMLOG("NmAttachmentListItem::mouseReleasedEvent"); |
|
228 if ( mTimer && mButtonPressed ){ |
|
229 emit itemActivated(); |
|
230 mButtonPressed = false; |
|
231 mTimer->stop(); |
|
232 } |
|
233 } |
|
234 |
|
235 /*! |
|
236 Hides the download progress bar |
222 Hides the download progress bar |
237 */ |
223 */ |
238 void NmAttachmentListItem::removeProgressBar() |
224 void NmAttachmentListItem::removeProgressBar() |
239 { |
225 { |
|
226 NM_FUNCTION; |
|
227 |
240 if ( mProgressBar ){ |
228 if ( mProgressBar ){ |
241 HbStyle::setItemName( mProgressBar, "" ); |
229 HbStyle::setItemName( mProgressBar, "" ); |
242 mProgressBar->deleteLater(); |
230 mProgressBar->deleteLater(); |
243 mProgressBar = 0; |
231 mProgressBar = 0; |
244 repolish(); |
232 repolish(); |
245 } |
233 } |
246 } |
234 } |
247 |
235 |
248 /*! |
|
249 |
|
250 */ |
|
251 void NmAttachmentListItem::longPressedActivated() |
|
252 { |
|
253 //check first if button is not released already |
|
254 if ( mButtonPressed ){ |
|
255 NMLOG("NmAttachmentListItem::longPressedActivated"); |
|
256 emit itemLongPressed(mLongPressedPoint); |
|
257 mButtonPressed = false; |
|
258 } |
|
259 } |
|
260 |
236 |
261 /*! |
237 /*! |
262 This function returns screen size depending on the orientation. |
238 This function returns screen size depending on the orientation. |
263 Function is copied from NmApplication. |
239 Function is copied from NmApplication. |
264 */ |
240 */ |
265 QSize NmAttachmentListItem::screenSize(Qt::Orientation orientation) |
241 QSize NmAttachmentListItem::screenSize(Qt::Orientation orientation) |
266 { |
242 { |
|
243 NM_FUNCTION; |
|
244 |
267 QSize ret(0,0); |
245 QSize ret(0,0); |
268 HbDeviceProfile currentP = HbDeviceProfile::current(); |
246 HbDeviceProfile currentP = HbDeviceProfile::current(); |
269 HbDeviceProfile altP(currentP.alternateProfileName()); |
247 HbDeviceProfile altP(currentP.alternateProfileName()); |
270 QSize curPSize = currentP.logicalSize(); |
248 QSize curPSize = currentP.logicalSize(); |
271 QSize altPSize = altP.logicalSize(); |
249 QSize altPSize = altP.logicalSize(); |
288 } |
266 } |
289 } |
267 } |
290 return ret; |
268 return ret; |
291 } |
269 } |
292 |
270 |
|
271 /*! |
|
272 This function handles gestures |
|
273 */ |
|
274 void NmAttachmentListItem::gestureEvent(QGestureEvent *event) |
|
275 { |
|
276 NM_FUNCTION; |
|
277 |
|
278 if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
|
279 switch(tap->tapStyleHint()) { |
|
280 case HbTapGesture::Tap: |
|
281 { |
|
282 if (tap->state() == Qt::GestureFinished) { |
|
283 emit itemActivated(); |
|
284 } |
|
285 } |
|
286 break; |
|
287 |
|
288 case HbTapGesture::TapAndHold: |
|
289 { |
|
290 if (tap->state() == Qt::GestureFinished) { |
|
291 emit itemLongPressed(event->mapToGraphicsScene(tap->position())); |
|
292 } |
|
293 } |
|
294 break; |
|
295 } |
|
296 } |
|
297 else { |
|
298 HbWidget::gestureEvent(event); |
|
299 } |
|
300 } |
|
301 |
|
302 |