101 |
102 |
102 /*! |
103 /*! |
103 Constructs a new NmAttachmentListWidget with \a parent. |
104 Constructs a new NmAttachmentListWidget with \a parent. |
104 */ |
105 */ |
105 NmAttachmentListWidget::NmAttachmentListWidget(QGraphicsItem *parent) |
106 NmAttachmentListWidget::NmAttachmentListWidget(QGraphicsItem *parent) |
106 : HbWidget( parent ), |
107 : HbWidget( parent ), |
107 mLayout(NULL), |
108 mLayout(NULL), |
108 mOrientation(Qt::Vertical) |
109 mOrientation(Qt::Vertical) |
109 { |
110 { |
110 NM_FUNCTION; |
111 NM_FUNCTION; |
111 |
112 |
112 init( ); |
113 init( ); |
113 } |
114 } |
114 |
115 |
115 |
116 |
116 /*! |
117 /*! |
117 Destructor. |
118 Destructor. |
118 */ |
119 */ |
119 NmAttachmentListWidget::~NmAttachmentListWidget( ) |
120 NmAttachmentListWidget::~NmAttachmentListWidget( ) |
120 { |
121 { |
121 NM_FUNCTION; |
122 NM_FUNCTION; |
122 |
123 |
123 qDeleteAll(mItemList); |
124 qDeleteAll(mItemList); |
124 |
125 |
125 mItemList.clear(); |
126 mItemList.clear(); |
126 |
127 |
127 } |
128 } |
128 |
129 |
129 /*! |
130 /*! |
130 Setter for items text color override. This fucntion can be used |
131 Setter for items text color override. This fucntion can be used |
131 if theme background is not used and text needs to be shown in diferent color. |
132 if theme background is not used and text needs to be shown in diferent color. |
132 */ |
133 */ |
133 void NmAttachmentListWidget::setTextColor(const QColor color) |
134 void NmAttachmentListWidget::setTextColor(const QColor color) |
134 { |
135 { |
135 NM_FUNCTION; |
136 NM_FUNCTION; |
136 |
137 |
137 mTextColor=color; |
138 mTextColor=color; |
|
139 } |
|
140 |
|
141 |
|
142 /*! |
|
143 Sets the background color. This method can be used to override the |
|
144 default background color set by the current theme. |
|
145 |
|
146 \param color The new background color. |
|
147 */ |
|
148 void NmAttachmentListWidget::setBackgroundColor(const QColor color) |
|
149 { |
|
150 NM_FUNCTION; |
|
151 mBackgroundColor = color; |
138 } |
152 } |
139 |
153 |
140 |
154 |
141 /*! |
155 /*! |
142 Inserts attachment to given index. If index already contains data, |
156 Inserts attachment to given index. If index already contains data, |
143 old one will be moved to next. |
157 old one will be moved to next. |
144 */ |
158 */ |
145 void NmAttachmentListWidget::insertAttachment( |
159 void NmAttachmentListWidget::insertAttachment( |
146 int index, |
160 int index, |
147 const QString &fileName, |
161 const QString &fileName, |
148 const QString &fileSize) |
162 const QString &fileSize) |
149 { |
163 { |
150 NM_FUNCTION; |
164 NM_FUNCTION; |
151 |
165 |
152 NmAttachmentListItem *item = new NmAttachmentListItem(this); |
166 NmAttachmentListItem *item = new NmAttachmentListItem(this); |
|
167 |
|
168 if (mBackgroundColor.isValid()) { |
|
169 item->setBackgroundColor(mBackgroundColor); |
|
170 } |
|
171 |
153 item->setObjectName(QString("nmattachmentlistitem_%1").arg(index)); |
172 item->setObjectName(QString("nmattachmentlistitem_%1").arg(index)); |
154 |
173 |
155 //connect to signals |
174 //connect to signals |
156 connect(item, SIGNAL(itemActivated()), this, SLOT(handleItemActivated())); |
175 connect(item, SIGNAL(itemActivated()), this, SLOT(handleItemActivated())); |
157 connect(item, SIGNAL(itemLongPressed(QPointF)), this, SLOT(handleLongPressed(QPointF))); |
176 connect(item, SIGNAL(itemLongPressed(QPointF)), this, SLOT(handleLongPressed(QPointF))); |
158 |
177 |
159 //set texts |
178 //set texts |
160 item->setTextColor(checkColor()); |
179 item->setTextColor(checkColor()); |
161 item->setFileNameText(fileName); |
180 item->setFileNameText(fileName); |
162 item->setFileSizeText(fileSize); |
181 item->setFileSizeText(fileSize); |
163 |
182 |
164 //finally add item to item's list |
183 //finally add item to item's list |
165 mItemList.insert(index,item); |
184 mItemList.insert(index,item); |
196 |
215 |
197 /*! |
216 /*! |
198 Set attachment file size. |
217 Set attachment file size. |
199 */ |
218 */ |
200 void NmAttachmentListWidget::setAttachmentSize( |
219 void NmAttachmentListWidget::setAttachmentSize( |
201 int index, |
220 int index, |
202 const QString &fileSize) |
221 const QString &fileSize) |
203 { |
222 { |
204 NM_FUNCTION; |
223 NM_FUNCTION; |
205 |
224 |
206 if (index>=0 && index<mItemList.count()) { |
225 if (index>=0 && index<mItemList.count()) { |
207 mItemList.at(index)->setFileSizeText(fileSize); |
226 mItemList.at(index)->setFileSizeText(fileSize); |
208 } |
227 } |
209 } |
228 } |
210 |
229 |
211 /*! |
230 /*! |
212 Returns attachment(s) count. |
231 Returns attachment(s) count. |
213 */ |
232 */ |
214 int NmAttachmentListWidget::count() const |
233 int NmAttachmentListWidget::count() const |
215 { |
234 { |
216 NM_FUNCTION; |
235 NM_FUNCTION; |
217 |
236 |
218 return mItemList.count(); |
237 return mItemList.count(); |
219 } |
238 } |
220 |
239 |
221 /*! |
240 /*! |
222 Returns value of item, otherwise -1 if index not found from list. |
241 Returns value of item, otherwise -1 if index not found from list. |
223 */ |
242 */ |
224 int NmAttachmentListWidget::progressValue(int index) const |
243 int NmAttachmentListWidget::progressValue(int index) const |
225 { |
244 { |
226 NM_FUNCTION; |
245 NM_FUNCTION; |
227 |
246 |
228 int ret(NmNotFoundError); |
247 int ret(NmNotFoundError); |
229 if(index >= 0 && index < mItemList.count()){ |
248 if(index >= 0 && index < mItemList.count()){ |
230 ret = mItemList.at(index)->progressBarValue(); |
249 ret = mItemList.at(index)->progressBarValue(); |
231 } |
250 } |
232 return ret; |
251 return ret; |
233 } |
252 } |
234 |
253 |
235 /*! |
254 /*! |
236 Hides progress of item, if index is negative or creater |
255 Hides progress of item, if index is negative or creater |
237 than last index function does nothing |
256 than last index function does nothing |
238 */ |
257 */ |
239 void NmAttachmentListWidget::hideProgressBar(int index) |
258 void NmAttachmentListWidget::hideProgressBar(int index) |
240 { |
259 { |
241 NM_FUNCTION; |
260 NM_FUNCTION; |
242 |
261 |
243 if(index >= 0 && index < mItemList.count()){ |
262 if(index >= 0 && index < mItemList.count()){ |
244 mItemList.at(index)->hideProgressBar(); |
263 mItemList.at(index)->hideProgressBar(); |
245 } |
264 } |
246 } |
265 } |
247 |
266 |
253 QPainter *painter, |
272 QPainter *painter, |
254 const QStyleOptionGraphicsItem *option, |
273 const QStyleOptionGraphicsItem *option, |
255 QWidget *widget) |
274 QWidget *widget) |
256 { |
275 { |
257 NM_FUNCTION; |
276 NM_FUNCTION; |
258 |
277 |
259 Q_UNUSED(option); |
278 Q_UNUSED(option); |
260 Q_UNUSED(widget); |
279 Q_UNUSED(widget); |
261 if (painter&&mLayout){ |
280 if (painter&&mLayout){ |
262 painter->save(); |
281 painter->save(); |
263 |
282 |
264 // Use text color as a line color if set, otherwise use theme |
283 // Use text color as a line color if set, otherwise use theme |
265 // normal list content color. |
284 // normal list content color. |
266 painter->setPen(checkColor()); |
285 painter->setPen(checkColor()); |
267 painter->setOpacity(NmItemLineOpacity); |
286 painter->setOpacity(NmItemLineOpacity); |
268 // Draw line after each item |
287 // Draw line after each item |
269 int rowCount = mLayout->rowCount(); |
288 int rowCount = mLayout->rowCount(); |
270 QRectF layoutRect = mLayout->geometry (); |
289 QRectF layoutRect = mLayout->geometry (); |
271 for (int i=0;i<rowCount;i++){ |
290 for (int i=0;i<rowCount;i++){ |
272 QGraphicsLayoutItem *item = mLayout->itemAt(i,0); |
291 QGraphicsLayoutItem *item = mLayout->itemAt(i,0); |
273 if (item){ |
292 if (item){ |
274 QRectF itemRect = item->geometry(); |
293 qreal offsetY = 0.5; |
275 QLineF line1( itemRect.topLeft().x(), itemRect.bottomRight().y(), |
294 QRectF itemRect = item->geometry(); |
276 layoutRect.bottomRight().x(), itemRect.bottomRight().y()); |
295 QLineF line1( itemRect.topLeft().x(), itemRect.bottomRight().y()+offsetY, |
277 painter->drawLine(line1); |
296 layoutRect.bottomRight().x(), itemRect.bottomRight().y()+offsetY); |
278 } |
297 painter->drawLine(line1); |
|
298 } |
279 } |
299 } |
280 painter->restore(); |
300 painter->restore(); |
281 } |
301 } |
282 } |
302 } |
283 |
303 |
314 |
334 |
315 //construct UI after orientation has been figured out |
335 //construct UI after orientation has been figured out |
316 constructUi(); |
336 constructUi(); |
317 |
337 |
318 //set flags |
338 //set flags |
319 setFlag(QGraphicsItem::ItemIsFocusable); |
339 setFlag(QGraphicsItem::ItemIsFocusable); |
320 setFlag(QGraphicsItem::ItemHasNoContents,false); |
340 setFlag(QGraphicsItem::ItemHasNoContents,false); |
321 } |
341 } |
322 |
342 |
323 /*! |
343 /*! |
324 Helper function for constructing UI components. |
344 Helper function for constructing UI components. |
325 */ |
345 */ |
326 void NmAttachmentListWidget::constructUi() |
346 void NmAttachmentListWidget::constructUi() |
327 { |
347 { |
328 NM_FUNCTION; |
348 NM_FUNCTION; |
329 |
349 |
330 setObjectName(QString(ATTACHMENT_WIDGET)); |
350 setObjectName(QString(ATTACHMENT_WIDGET)); |
331 HbDocumentLoader loader; |
351 HbDocumentLoader loader; |
332 bool loadingOk = false; |
352 bool loadingOk = false; |
333 |
353 |
334 //Pass this widget to documentloader |
354 //Pass this widget to documentloader |
353 Helper slot for handling longpressed signals. |
373 Helper slot for handling longpressed signals. |
354 */ |
374 */ |
355 void NmAttachmentListWidget::handleLongPressed(QPointF point) |
375 void NmAttachmentListWidget::handleLongPressed(QPointF point) |
356 { |
376 { |
357 NM_FUNCTION; |
377 NM_FUNCTION; |
358 |
378 |
359 QObject *sender = QObject::sender(); |
379 QObject *sender = QObject::sender(); |
360 int index = findItem(sender); |
380 int index = findItem(sender); |
361 if(NmNotFoundError != index){ |
381 if(NmNotFoundError != index){ |
362 emit longPressed(index, point); |
382 emit longPressed(index, point); |
363 } |
383 } |
451 Helper function for rearrange layout after removing or layout change |
471 Helper function for rearrange layout after removing or layout change |
452 */ |
472 */ |
453 void NmAttachmentListWidget::rearrangeLayout() |
473 void NmAttachmentListWidget::rearrangeLayout() |
454 { |
474 { |
455 NM_FUNCTION; |
475 NM_FUNCTION; |
456 |
476 |
457 if(!mLayout) { |
477 if(!mLayout) { |
458 NM_ERROR(1,"NmAttachmentListWidget::rearrangeLayout: Layout loading failed!"); |
478 NM_ERROR(1,"NmAttachmentListWidget::rearrangeLayout: Layout loading failed!"); |
459 return; |
479 return; |
460 } |
480 } |
461 |
481 |
462 //remove all items from the layout |
482 //remove all items from the layout |
463 int count(mLayout->count()); |
483 int count(mLayout->count()); |
464 for(int i = count - 1; i >= 0; --i){ |
484 for(int i = count - 1; i >= 0; --i){ |
465 mLayout->removeAt(i); |
485 mLayout->removeAt(i); |
466 } |
486 } |
467 |
487 |
468 //then add them back |
488 //then add them back |
469 QColor textColor = checkColor(); |
489 QColor textColor = checkColor(); |
470 foreach(NmAttachmentListItem *item, mItemList){ |
490 foreach(NmAttachmentListItem *item, mItemList){ |
471 item->setTextColor(textColor); |
491 item->setTextColor(textColor); |
472 insertItemToLayout(item); |
492 insertItemToLayout(item); |
473 } |
493 } |
474 } |
494 } |