|
1 /* |
|
2 * Copyright (c) 2010 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: Attachment list item widget |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "nmailuiwidgetsheaders.h" |
|
19 |
|
20 static const QString FILE_PATH_WIDGETML = ":nmattachmentlistitem.widgetml"; |
|
21 static const QString FILE_PATH_CSS = ":nmattachmentlistitem.css"; |
|
22 |
|
23 static const int PROGRESSBAR_MIN = 0; |
|
24 static const int PROGRESSBAR_MAX = 100; |
|
25 static const int PROGRESSBAR_HIDE_COUNTDOWN = 5000; |
|
26 static const int LONGPRESS_TIMER = 2000; |
|
27 |
|
28 |
|
29 /*! |
|
30 @nmailuiwidgets |
|
31 \class NmAttachmentListItem |
|
32 |
|
33 \brief The NmAttachmentListItem widget provides for showing a single attachment with file size and |
|
34 download progress in the attachment list. |
|
35 |
|
36 |
|
37 |
|
38 */ |
|
39 |
|
40 |
|
41 /*! |
|
42 Constructs a new NmAttachmentListItem with \a parent. |
|
43 */ |
|
44 NmAttachmentListItem::NmAttachmentListItem(QGraphicsItem *parent) |
|
45 : HbWidget( parent ), |
|
46 mFileNameText(NULL), |
|
47 mFileSizeText(NULL), |
|
48 mProgressBar(NULL), |
|
49 mTimer(NULL), |
|
50 mButtonPressed(false), |
|
51 mLongPressedPoint(0,0) |
|
52 { |
|
53 init( ); |
|
54 } |
|
55 |
|
56 |
|
57 /*! |
|
58 Destructor. |
|
59 */ |
|
60 NmAttachmentListItem::~NmAttachmentListItem( ) |
|
61 { |
|
62 HbStyleLoader::unregisterFilePath(FILE_PATH_WIDGETML); |
|
63 HbStyleLoader::unregisterFilePath(FILE_PATH_CSS); |
|
64 } |
|
65 |
|
66 /*! |
|
67 Set the texts to be displayed in the file name and file size items |
|
68 |
|
69 */ |
|
70 void NmAttachmentListItem::setTextItems(const QString &fileName, const QString &fileSize) |
|
71 { |
|
72 mFileNameText->setText(fileName); |
|
73 mFileSizeText->setText(fileSize); |
|
74 } |
|
75 |
|
76 |
|
77 /*! |
|
78 Set the download progress bar value (0-100)%, if value is 0 progress bar is hidden |
|
79 */ |
|
80 void NmAttachmentListItem::setProgressBarValue(const int value) |
|
81 { |
|
82 //first check if value is 0 or below -> hide progressbar |
|
83 if ( 0 >= value ){ |
|
84 removeProgressBar(); |
|
85 return; |
|
86 } |
|
87 |
|
88 if ( !mProgressBar ){ |
|
89 mProgressBar = new HbProgressBar(HbProgressBar::SimpleProgressBar, this); |
|
90 mProgressBar->setObjectName("attachmentlistitem_progress"); |
|
91 mProgressBar->setRange(PROGRESSBAR_MIN,PROGRESSBAR_MAX); |
|
92 HbStyle::setItemName( mProgressBar, "progressbar" ); |
|
93 repolish(); |
|
94 } |
|
95 mProgressBar->setProgressValue(value); |
|
96 |
|
97 //start hiding count down |
|
98 if(PROGRESSBAR_MAX <= value){ |
|
99 QTimer::singleShot(PROGRESSBAR_HIDE_COUNTDOWN,this, SLOT(removeProgressBar())); |
|
100 } |
|
101 } |
|
102 |
|
103 /*! |
|
104 Get the download progress bar value |
|
105 */ |
|
106 int NmAttachmentListItem::progressBarValue() const |
|
107 { |
|
108 int ret = 0; |
|
109 if ( mProgressBar ){ |
|
110 ret = mProgressBar->progressValue(); |
|
111 } |
|
112 |
|
113 return ret; |
|
114 } |
|
115 |
|
116 /*! |
|
117 Initialize |
|
118 */ |
|
119 void NmAttachmentListItem::init( ) |
|
120 { |
|
121 constructUi(); |
|
122 |
|
123 //set default values |
|
124 setFlag(QGraphicsItem::ItemIsFocusable); |
|
125 setFlag(QGraphicsItem::ItemIsSelectable); |
|
126 |
|
127 //set temporary longpress timer |
|
128 mTimer = new QTimer(this); |
|
129 connect(mTimer, SIGNAL(timeout()), this, SLOT(longPressedActivated())); |
|
130 } |
|
131 |
|
132 /*! |
|
133 Constructs the UI, sets style itemnames etc. |
|
134 */ |
|
135 void NmAttachmentListItem::constructUi() |
|
136 { |
|
137 //construct default ui. |
|
138 HbStyleLoader::registerFilePath(FILE_PATH_WIDGETML); |
|
139 HbStyleLoader::registerFilePath(FILE_PATH_CSS); |
|
140 |
|
141 mFileNameText = new HbTextItem(this); |
|
142 mFileNameText->setObjectName("nmattachmentlistitem_filenametext"); |
|
143 HbStyle::setItemName( mFileNameText, "filename" ); |
|
144 |
|
145 mFileSizeText = new HbTextItem(this); |
|
146 mFileSizeText->setObjectName("nmattachmentlistitem_filenamesize"); |
|
147 HbStyle::setItemName( mFileSizeText, "filesize" ); |
|
148 mFileSizeText->setElideMode(Qt::ElideNone); |
|
149 |
|
150 } |
|
151 |
|
152 |
|
153 /*! |
|
154 \reimp |
|
155 */ |
|
156 void NmAttachmentListItem::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
|
157 { |
|
158 NMLOG("NmAttachmentListItem::mousePressEvent"); |
|
159 |
|
160 mButtonPressed = true; |
|
161 mLongPressedPoint = event->scenePos(); |
|
162 mTimer->start(LONGPRESS_TIMER); |
|
163 } |
|
164 |
|
165 /*! |
|
166 \reimp |
|
167 */ |
|
168 void NmAttachmentListItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
169 { |
|
170 Q_UNUSED(event); |
|
171 NMLOG("NmAttachmentListItem::mouseReleasedEvent"); |
|
172 if ( mButtonPressed ){ |
|
173 emit itemActivated(); |
|
174 mButtonPressed = false; |
|
175 mTimer->stop(); |
|
176 } |
|
177 } |
|
178 |
|
179 /*! |
|
180 Hides the download progress bar |
|
181 */ |
|
182 void NmAttachmentListItem::removeProgressBar() |
|
183 { |
|
184 if ( mProgressBar ){ |
|
185 HbStyle::setItemName( mProgressBar, "" ); |
|
186 mProgressBar->deleteLater(); |
|
187 mProgressBar = 0; |
|
188 repolish(); |
|
189 } |
|
190 } |
|
191 |
|
192 /*! |
|
193 |
|
194 */ |
|
195 void NmAttachmentListItem::longPressedActivated() |
|
196 { |
|
197 //check first if button is not released already |
|
198 if ( mButtonPressed ){ |
|
199 NMLOG("NmAttachmentListItem::longPressedActivated"); |
|
200 emit itemLongPressed(mLongPressedPoint); |
|
201 mButtonPressed = false; |
|
202 mTimer->stop(); |
|
203 } |
|
204 } |
|
205 |