|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cnthistoryviewitem.h" |
|
19 |
|
20 #include <cnthistorymodel.h> |
|
21 #include <hbframedrawer.h> |
|
22 #include <hbframeitem.h> |
|
23 #include <QGraphicsWidget> |
|
24 |
|
25 #define NEW_EVENT_FRAME "qtg_fr_list_new_item" |
|
26 #define INCOMING_FOCUS_FRAME "qtg_fr_convlist_received_pressed" |
|
27 #define OUTGOING_FOCUS_FRAME "qtg_fr_convlist_sent_pressed" |
|
28 |
|
29 //--------------------------------------------------------------- |
|
30 // HbListViewItem::HbListViewItem |
|
31 // Constructor |
|
32 //--------------------------------------------------------------- |
|
33 CntHistoryViewItem::CntHistoryViewItem(QGraphicsItem* parent) |
|
34 : HbListViewItem(parent), |
|
35 mIncoming(false), |
|
36 mNewMessage(false), |
|
37 mNewItem(NULL), |
|
38 mFocusItem(NULL) |
|
39 { |
|
40 } |
|
41 |
|
42 //--------------------------------------------------------------- |
|
43 // HbListViewItem::createItem |
|
44 // Create a new decorator item. |
|
45 //--------------------------------------------------------------- |
|
46 HbAbstractViewItem* CntHistoryViewItem::createItem() |
|
47 { |
|
48 return new CntHistoryViewItem(*this); |
|
49 } |
|
50 |
|
51 //--------------------------------------------------------------- |
|
52 // HbListViewItem::updateChildItems |
|
53 // |
|
54 //--------------------------------------------------------------- |
|
55 void CntHistoryViewItem::updateChildItems() |
|
56 { |
|
57 int flags = modelIndex().data(CntFlagsRole).toInt(); |
|
58 mIncoming = flags & CntIncoming ? true : false; |
|
59 mNewMessage = flags & CntUnseen ? true : false; |
|
60 |
|
61 if (mNewMessage) |
|
62 { |
|
63 if (!mNewItem) |
|
64 { |
|
65 mNewItem = new HbFrameItem(NEW_EVENT_FRAME, HbFrameDrawer::ThreePiecesVertical, this); |
|
66 style()->setItemName(mNewItem, "newitem"); |
|
67 } |
|
68 } |
|
69 else |
|
70 { |
|
71 if (mNewItem) |
|
72 { |
|
73 delete mNewItem; |
|
74 mNewItem = NULL; |
|
75 } |
|
76 } |
|
77 |
|
78 HbListViewItem::updateChildItems(); |
|
79 } |
|
80 |
|
81 //--------------------------------------------------------------- |
|
82 // HbAbstractViewItem::pressStateChanged |
|
83 // This function is called whenever item press state changes. |
|
84 //--------------------------------------------------------------- |
|
85 void CntHistoryViewItem::pressStateChanged(bool pressed, bool animate) |
|
86 { |
|
87 Q_UNUSED(animate); |
|
88 if (pressed) |
|
89 { |
|
90 if (!mFocusItem) |
|
91 { |
|
92 // focus frame position can't be read from widgetml, we set it manually |
|
93 QRectF frameRect = HbWidget::primitive("frame")->boundingRect(); |
|
94 QPointF framePoint = HbWidget::primitive("frame")->pos(); |
|
95 |
|
96 frameRect.moveTo(framePoint); |
|
97 |
|
98 if (mIncoming) |
|
99 { |
|
100 mFocusItem = new HbFrameItem(INCOMING_FOCUS_FRAME, HbFrameDrawer::NinePieces, this); |
|
101 } |
|
102 else |
|
103 { |
|
104 mFocusItem = new HbFrameItem(OUTGOING_FOCUS_FRAME, HbFrameDrawer::NinePieces, this); |
|
105 } |
|
106 |
|
107 mFocusItem->setGeometry(frameRect); |
|
108 mFocusItem->setZValue(-1.0); |
|
109 style()->setItemName(mFocusItem, "focusframe"); |
|
110 } |
|
111 } |
|
112 else |
|
113 { |
|
114 if (mFocusItem) |
|
115 { |
|
116 delete mFocusItem; |
|
117 mFocusItem = NULL; |
|
118 } |
|
119 } |
|
120 } |
|
121 |
|
122 bool CntHistoryViewItem::event(QEvent* e) |
|
123 { |
|
124 bool result; |
|
125 if (e->type() == QEvent::GraphicsSceneResize) |
|
126 { |
|
127 // HbAbstractItemView has a performance improvement when drawing backrounds but seems |
|
128 // to screw the layout of history view items. This workaround fixes the issue. There should |
|
129 // be minimal performance drawbacks since GraphicsSceneResize events are quite few. |
|
130 // TODO: Remove this once Orbit changes their implementation. Not known when |
|
131 QGraphicsWidget *frame = static_cast<QGraphicsWidget*>(primitive("frame")); |
|
132 QRectF frameGeometry = frame->geometry(); |
|
133 result = HbListViewItem::event(e); |
|
134 frame->setGeometry(frameGeometry); |
|
135 } |
|
136 else |
|
137 { |
|
138 result = HbListViewItem::event(e); |
|
139 } |
|
140 return result; |
|
141 } |
|
142 |
|
143 // EOF |