|
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 <HbAbstractItemView> |
|
20 #include <HbStyleLoader> |
|
21 #include <QPainter> |
|
22 #include <caitemmodel.h> |
|
23 #include "hsmenuitemmodel.h" |
|
24 |
|
25 #include "hslistviewitem.h" |
|
26 |
|
27 |
|
28 // TODO: this is only temporary class for show progress bar. |
|
29 // It should be remove when fix from orbit will be in official platfrom. |
|
30 // Remove it from header too. |
|
31 |
|
32 #ifdef COVERAGE_MEASUREMENT |
|
33 #pragma CTC SKIP |
|
34 #endif //COVERAGE_MEASUREMENT |
|
35 void HsProgressBar::paint(QPainter * painter, |
|
36 const QStyleOptionGraphicsItem * option, |
|
37 QWidget * widget) |
|
38 { |
|
39 Q_UNUSED(widget) |
|
40 QStyleOptionGraphicsItem pixmapOption(*option); |
|
41 foreach (QGraphicsItem *child, childItems()) { |
|
42 painter->save(); |
|
43 painter->translate(child->pos()); |
|
44 pixmapOption.exposedRect = child->boundingRect(); |
|
45 child->paint(painter, &pixmapOption, 0); |
|
46 |
|
47 foreach (QGraphicsItem *child2, child->childItems()) { |
|
48 if (child2->isVisible()) { |
|
49 painter->save(); |
|
50 painter->translate(child2->pos()); |
|
51 pixmapOption.exposedRect = child2->boundingRect(); |
|
52 child2->paint(painter, &pixmapOption, 0); |
|
53 painter->restore(); |
|
54 } |
|
55 } |
|
56 painter->restore(); |
|
57 } |
|
58 } |
|
59 #ifdef COVERAGE_MEASUREMENT |
|
60 #pragma CTC ENDSKIP |
|
61 #endif //COVERAGE_MEASUREMENT |
|
62 |
|
63 |
|
64 HsListViewItem::HsListViewItem(QGraphicsItem* parent) : |
|
65 HbListViewItem(parent), progress(0), isProgress(false) |
|
66 { |
|
67 setGraphicsSize(LargeIcon); |
|
68 if (this == prototype()) { |
|
69 HbStyleLoader::registerFilePath(":/layout/hslistviewitem.css"); |
|
70 } |
|
71 } |
|
72 |
|
73 HsListViewItem::~HsListViewItem() |
|
74 { |
|
75 if (this == prototype()) { |
|
76 HbStyleLoader::unregisterFilePath(":/layout/hslistviewitem.css"); |
|
77 HbStyleLoader::unregisterFilePath(":/layout/hslistviewitem.widgetml"); |
|
78 } |
|
79 } |
|
80 |
|
81 void HsListViewItem::updateChildItems() |
|
82 { |
|
83 HbListViewItem::updateChildItems(); |
|
84 |
|
85 EntryFlags flags = modelIndex().data( |
|
86 CaItemModel::FlagsRole).value<EntryFlags> (); |
|
87 isProgress = false; |
|
88 if (flags & UninstallEntryFlag) { |
|
89 isProgress = true; |
|
90 if (!progress) { |
|
91 progress = new HsProgressBar(this); |
|
92 HbStyle::setItemName(progress, "progress"); |
|
93 progress->setRange(0, 100); |
|
94 HbEffect::disable(progress); |
|
95 repolish(); |
|
96 } |
|
97 int progresVal = modelIndex().data( |
|
98 CaItemModel::UninstalRole).toInt(); |
|
99 progress->setProgressValue(progresVal); |
|
100 } else if (progress) { |
|
101 delete progress; |
|
102 progress = 0; |
|
103 repolish(); |
|
104 } |
|
105 // hide text-2 if we have to |
|
106 foreach (QGraphicsItem * item, this->childItems()) { |
|
107 if (HbStyle::itemName(item) == "text-2") { |
|
108 item->setVisible(!isProgress); |
|
109 break; |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 HbAbstractViewItem* HsListViewItem::createItem() |
|
115 { |
|
116 return new HsListViewItem(*this); |
|
117 } |
|
118 |
|
119 |
|
120 void HsListViewItem::polish(HbStyleParameters& params) |
|
121 { |
|
122 if (isProgress) { |
|
123 HbStyleLoader::registerFilePath(":/layout/hslistviewitem.widgetml"); |
|
124 } |
|
125 HbListViewItem::setProperty("progress", isProgress); |
|
126 HbListViewItem::polish(params); |
|
127 if (isProgress) { |
|
128 HbStyleLoader::unregisterFilePath(":/layout/hslistviewitem.widgetml"); |
|
129 } |
|
130 } |
|
131 |