16 */ |
16 */ |
17 |
17 |
18 #include "cnthistoryviewitem.h" |
18 #include "cnthistoryviewitem.h" |
19 |
19 |
20 #include <cnthistorymodel.h> |
20 #include <cnthistorymodel.h> |
|
21 #include <hbframedrawer.h> |
|
22 #include <hbframeitem.h> |
|
23 |
|
24 #define NEW_EVENT_FRAME "qtg_fr_list_new_item" |
21 |
25 |
22 //--------------------------------------------------------------- |
26 //--------------------------------------------------------------- |
23 // HbListViewItem::HbListViewItem |
27 // HbListViewItem::HbListViewItem |
24 // Constructor |
28 // Constructor |
25 //--------------------------------------------------------------- |
29 //--------------------------------------------------------------- |
26 CntHistoryViewItem::CntHistoryViewItem(QGraphicsItem* parent) |
30 CntHistoryViewItem::CntHistoryViewItem(QGraphicsItem* parent) |
27 : HbAbstractViewItem(parent), |
31 : HbListViewItem(parent), |
28 itemWidget(NULL) |
32 mIncoming(false), |
|
33 mNewMessage(false), |
|
34 mNewItem(NULL) |
29 { |
35 { |
30 } |
36 } |
31 |
37 |
32 //--------------------------------------------------------------- |
38 //--------------------------------------------------------------- |
33 // HbListViewItem::createItem |
39 // HbListViewItem::createItem |
34 // Create a new decorator item. |
40 // Create a new decorator item. |
35 //--------------------------------------------------------------- |
41 //--------------------------------------------------------------- |
36 HbAbstractViewItem* CntHistoryViewItem::createItem() |
42 HbAbstractViewItem* CntHistoryViewItem::createItem() |
37 { |
43 { |
38 return new CntHistoryViewItem(*this); |
44 return new CntHistoryViewItem(*this); |
39 } |
|
40 |
|
41 //--------------------------------------------------------------- |
|
42 // HbListViewItem::polish |
|
43 // |
|
44 //--------------------------------------------------------------- |
|
45 void CntHistoryViewItem::polish(HbStyleParameters& /*params*/) |
|
46 { |
|
47 } |
45 } |
48 |
46 |
49 //--------------------------------------------------------------- |
47 //--------------------------------------------------------------- |
50 // HbListViewItem::updateChildItems |
48 // HbListViewItem::updateChildItems |
51 // |
49 // |
52 //--------------------------------------------------------------- |
50 //--------------------------------------------------------------- |
53 void CntHistoryViewItem::updateChildItems() |
51 void CntHistoryViewItem::updateChildItems() |
54 { |
52 { |
55 QStringList data = modelIndex().data(Qt::DisplayRole).toStringList(); |
53 int flags = modelIndex().data(CntHistoryModel::FlagsRole).toInt(); |
56 QString iconName = modelIndex().data(Qt::DecorationRole).toString(); |
54 mIncoming = flags & CntHistoryModel::Incoming ? true : false; |
57 bool incoming = false; |
55 mNewMessage = flags & CntHistoryModel::Unseen ? true : false; |
58 bool newMessage = false; |
56 |
59 bool status = false; |
57 if (mNewMessage) |
60 if (modelIndex().data(CntHistoryModel::DirectionRole).toInt(&status) == CntHistoryModel::Incoming) { |
58 { |
61 incoming = true; |
59 if (!mNewItem) |
|
60 { |
|
61 mNewItem = new HbFrameItem(NEW_EVENT_FRAME, HbFrameDrawer::ThreePiecesVertical, this); |
|
62 style()->setItemName(mNewItem, "newitem"); |
|
63 } |
62 } |
64 } |
63 // This indication applies to smses only |
65 else |
64 if (modelIndex().data(CntHistoryModel::ItemTypeRole).toInt(&status) == CntHistoryModel::Message && |
66 { |
65 modelIndex().data(CntHistoryModel::SeenStatusRole).toInt(&status) == CntHistoryModel::Unseen) { |
67 if (mNewItem) |
66 newMessage = true; |
68 { |
|
69 delete mNewItem; |
|
70 mNewItem = NULL; |
|
71 } |
67 } |
72 } |
68 |
73 |
69 QGraphicsLinearLayout* currentLayout = static_cast<QGraphicsLinearLayout*>(layout()); |
74 HbListViewItem::updateChildItems(); |
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 } |
|
105 } |
75 } |
106 // EOF |
76 // EOF |