14 * Description: List View Item. |
14 * Description: List View Item. |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <hbnamespace.h> |
18 #include <hbnamespace.h> |
19 #include <HbProgressBar> |
19 #include <HbAbstractItemView> |
20 |
|
21 #include <HbStyleLoader> |
20 #include <HbStyleLoader> |
|
21 #include <QPainter> |
22 #include <caitemmodel.h> |
22 #include <caitemmodel.h> |
23 #include "hsmenuitemmodel.h" |
23 #include "hsmenuitemmodel.h" |
24 |
24 |
25 #include "hslistviewitem.h" |
25 #include "hslistviewitem.h" |
26 |
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 |
27 HsListViewItem::HsListViewItem(QGraphicsItem* parent) : |
64 HsListViewItem::HsListViewItem(QGraphicsItem* parent) : |
28 HbListViewItem(parent), progress(0), isProgress(false) |
65 HbListViewItem(parent), progress(0), isProgress(false) |
29 { |
66 { |
30 setGraphicsSize(LargeIcon); |
67 setGraphicsSize(LargeIcon); |
31 HbStyleLoader::registerFilePath(":/layout/hslistviewitem.css"); |
68 if (this == prototype()) { |
32 HbStyleLoader::registerFilePath(":/layout/hslistviewitem.widgetml"); |
69 HbStyleLoader::registerFilePath(":/layout/hslistviewitem.css"); |
|
70 } |
33 } |
71 } |
34 |
72 |
35 HsListViewItem::~HsListViewItem() |
73 HsListViewItem::~HsListViewItem() |
36 { |
74 { |
37 if (this == prototype()) { |
75 if (this == prototype()) { |
42 |
80 |
43 void HsListViewItem::updateChildItems() |
81 void HsListViewItem::updateChildItems() |
44 { |
82 { |
45 HbListViewItem::updateChildItems(); |
83 HbListViewItem::updateChildItems(); |
46 |
84 |
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( |
85 EntryFlags flags = modelIndex().data( |
58 CaItemModel::FlagsRole).value<EntryFlags> (); |
86 CaItemModel::FlagsRole).value<EntryFlags> (); |
59 isProgress = false; |
87 isProgress = false; |
60 if (flags & UninstallEntryFlag) { |
88 if (flags & UninstallEntryFlag) { |
61 isProgress = true; |
89 isProgress = true; |
62 if (!progress) { |
90 if (!progress) { |
63 progress = new HbProgressBar(this); |
91 progress = new HsProgressBar(this); |
|
92 HbStyle::setItemName(progress, "progress"); |
64 progress->setRange(0, 100); |
93 progress->setRange(0, 100); |
65 HbEffect::disable(progress); |
94 HbEffect::disable(progress); |
66 repolish(); |
95 repolish(); |
67 } |
96 } |
68 int progresVal = modelIndex().data( |
97 int progresVal = modelIndex().data( |
69 CaItemModel::UninstalRole).toInt(); |
98 CaItemModel::UninstalRole).toInt(); |
70 progress->setProgressValue(progresVal); |
99 progress->setProgressValue(progresVal); |
71 HbStyle::setItemName(progress, "progress"); |
|
72 if (!progress->isVisible()) { |
|
73 progress->setVisible(!progress->isVisible()); |
|
74 repolish(); |
|
75 } |
|
76 } else if (progress) { |
100 } else if (progress) { |
77 HbStyle::setItemName(progress, ""); |
101 delete progress; |
78 if (progress->isVisible()) { |
102 progress = 0; |
79 progress->setVisible(!progress->isVisible()); |
103 repolish(); |
80 repolish(); |
|
81 } |
|
82 } |
104 } |
83 // hide text-2 if we have to |
105 // hide text-2 if we have to |
84 foreach (QGraphicsItem * item, this->childItems()) { |
106 foreach (QGraphicsItem * item, this->childItems()) { |
85 if (HbStyle::itemName(item) == "text-2") { |
107 if (HbStyle::itemName(item) == "text-2") { |
86 item->setVisible(!isProgress); |
108 item->setVisible(!isProgress); |