|
1 /* |
|
2 * Copyright (c) 2009 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: List View Item. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbnamespace.h> |
|
19 #include <HbProgressBar> |
|
20 |
|
21 #include <HbStyleLoader> |
|
22 #include <caitemmodel.h> |
|
23 #include "hsmenuitemmodel.h" |
|
24 |
|
25 #include "hslistviewitem.h" |
|
26 |
|
27 HsListViewItem::HsListViewItem(QGraphicsItem* parent) : |
|
28 HbListViewItem(parent), progress(0), isProgress(false) |
|
29 { |
|
30 setGraphicsSize(LargeIcon); |
|
31 HbStyleLoader::registerFilePath(":/layout/hslistviewitem.css"); |
|
32 HbStyleLoader::registerFilePath(":/layout/hslistviewitem.widgetml"); |
|
33 } |
|
34 |
|
35 HsListViewItem::~HsListViewItem() |
|
36 { |
|
37 if (this == prototype()) { |
|
38 HbStyleLoader::unregisterFilePath(":/layout/hslistviewitem.css"); |
|
39 HbStyleLoader::unregisterFilePath(":/layout/hslistviewitem.widgetml"); |
|
40 } |
|
41 } |
|
42 |
|
43 void HsListViewItem::updateChildItems() |
|
44 { |
|
45 HbListViewItem::updateChildItems(); |
|
46 |
|
47 // DisplayRoles |
|
48 QVariant displayRole = modelIndex().data(Qt::DisplayRole); |
|
49 QStringList stringList; |
|
50 if (displayRole.isValid()) { |
|
51 if (displayRole.canConvert<QString>()) { |
|
52 stringList.append(displayRole.toString()); |
|
53 } else if (displayRole.canConvert<QStringList>()) { |
|
54 stringList = displayRole.toStringList(); |
|
55 } |
|
56 } |
|
57 EntryFlags flags = modelIndex().data( |
|
58 CaItemModel::FlagsRole).value<EntryFlags> (); |
|
59 isProgress = false; |
|
60 if (flags & UninstallEntryFlag) { |
|
61 isProgress = true; |
|
62 if (!progress) { |
|
63 progress = new HbProgressBar(this); |
|
64 progress->setRange(0, 100); |
|
65 repolish(); |
|
66 } |
|
67 int progresVal = modelIndex().data( |
|
68 CaItemModel::UninstalRole).toInt(); |
|
69 progress->setProgressValue(progresVal); |
|
70 HbStyle::setItemName(progress, "progress"); |
|
71 } else if (progress) { |
|
72 HbStyle::setItemName(progress, ""); |
|
73 delete progress; |
|
74 progress = 0; |
|
75 repolish(); |
|
76 } |
|
77 // hide text-2 if we have to |
|
78 foreach (QGraphicsItem * item, this->childItems()) { |
|
79 if (HbStyle::itemName(item) == "text-2") { |
|
80 item->setVisible(!isProgress); |
|
81 break; |
|
82 } |
|
83 } |
|
84 } |
|
85 |
|
86 HbAbstractViewItem* HsListViewItem::createItem() |
|
87 { |
|
88 return new HsListViewItem(*this); |
|
89 } |
|
90 |
|
91 |
|
92 void HsListViewItem::polish(HbStyleParameters& params) |
|
93 { |
|
94 HbListViewItem::setProperty("progress", isProgress); |
|
95 HbListViewItem::polish(params); |
|
96 } |