15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "cnthistoryviewitem.h" |
18 #include "cnthistoryviewitem.h" |
19 |
19 |
20 #include <mobhistorymodel.h> |
20 #include <cnthistorymodel.h> |
21 |
21 |
22 //--------------------------------------------------------------- |
22 //--------------------------------------------------------------- |
23 // HbListViewItem::HbListViewItem |
23 // HbListViewItem::HbListViewItem |
24 // Constructor |
24 // Constructor |
25 //--------------------------------------------------------------- |
25 //--------------------------------------------------------------- |
26 CntHistoryViewItem::CntHistoryViewItem(QGraphicsItem* parent) |
26 CntHistoryViewItem::CntHistoryViewItem(QGraphicsItem* parent) |
27 : HbAbstractViewItem(parent), |
27 : HbAbstractViewItem(parent), |
28 mLayout(0), |
28 itemWidget(NULL) |
29 itemWidget(0) |
|
30 { |
29 { |
31 } |
30 } |
32 |
31 |
33 //--------------------------------------------------------------- |
32 //--------------------------------------------------------------- |
34 // HbListViewItem::createItem |
33 // HbListViewItem::createItem |
51 // HbListViewItem::updateChildItems |
50 // HbListViewItem::updateChildItems |
52 // |
51 // |
53 //--------------------------------------------------------------- |
52 //--------------------------------------------------------------- |
54 void CntHistoryViewItem::updateChildItems() |
53 void CntHistoryViewItem::updateChildItems() |
55 { |
54 { |
56 //Create whole item layout |
|
57 if (!mLayout) { |
|
58 mLayout = new QGraphicsLinearLayout(this); |
|
59 mLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
|
60 mLayout->setOrientation(Qt::Horizontal); |
|
61 mLayout->setContentsMargins(0,0,0,0); |
|
62 } |
|
63 |
|
64 //Create item widget |
|
65 if(!itemWidget) |
|
66 { |
|
67 itemWidget = new CntHistoryViewItemWidget(this); |
|
68 mLayout->addItem(itemWidget); |
|
69 } |
|
70 |
|
71 //Update item widget content |
|
72 QStringList data = modelIndex().data(Qt::DisplayRole).toStringList(); |
55 QStringList data = modelIndex().data(Qt::DisplayRole).toStringList(); |
73 QString iconName = modelIndex().data(Qt::DecorationRole).toString(); |
56 QString iconName = modelIndex().data(Qt::DecorationRole).toString(); |
74 bool incoming = false; |
57 bool incoming = false; |
|
58 bool newMessage = false; |
75 bool status = false; |
59 bool status = false; |
76 if (modelIndex().data(MobHistoryModel::DirectionRole).toInt(&status) == 0) { |
60 if (modelIndex().data(CntHistoryModel::DirectionRole).toInt(&status) == CntHistoryModel::Incoming) { |
77 incoming = true; |
61 incoming = true; |
78 } |
62 } |
79 |
63 // This indication applies to smses only |
80 itemWidget->setDetails(data.at(0), data.at(1), data.at(2), iconName, incoming); |
64 if (modelIndex().data(CntHistoryModel::ItemTypeRole).toInt(&status) == CntHistoryModel::Message && |
81 |
65 modelIndex().data(CntHistoryModel::SeenStatusRole).toInt(&status) == CntHistoryModel::Unseen) { |
82 setLayout(mLayout); |
66 newMessage = true; |
|
67 } |
|
68 |
|
69 QGraphicsLinearLayout* currentLayout = static_cast<QGraphicsLinearLayout*>(layout()); |
|
70 |
|
71 if (currentLayout == NULL) { |
|
72 |
|
73 currentLayout = new QGraphicsLinearLayout(this); |
|
74 currentLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
|
75 currentLayout->setOrientation(Qt::Horizontal); |
|
76 currentLayout->setContentsMargins(0,0,0,0); |
|
77 |
|
78 //Create item widget |
|
79 itemWidget = new CntHistoryViewItemWidget(this); |
|
80 currentLayout->addItem(itemWidget); |
|
81 |
|
82 //Update item widget contents |
|
83 itemWidget->setDetails(data.at(0), data.at(1), data.at(2), iconName, incoming, newMessage); |
|
84 |
|
85 setLayout(currentLayout); |
|
86 |
|
87 } else { |
|
88 // Find the itemWidget item from the layout and remove it |
|
89 int i = 0; |
|
90 while( itemWidget != static_cast<CntHistoryViewItemWidget*>(currentLayout->itemAt(i)) ) { |
|
91 i++; |
|
92 } |
|
93 currentLayout->removeAt(i); |
|
94 delete itemWidget; |
|
95 |
|
96 //Create new item widget |
|
97 itemWidget = new CntHistoryViewItemWidget(this); |
|
98 currentLayout->addItem(itemWidget); |
|
99 |
|
100 //Update item widget contents |
|
101 itemWidget->setDetails(data.at(0), data.at(1), data.at(2), iconName, incoming, newMessage); |
|
102 |
|
103 updateGeometry(); |
|
104 } |
83 } |
105 } |
84 // EOF |
106 // EOF |