|
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 item for conference participant list. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QGraphicsLinearLayout> |
|
19 #include <hbiconitem.h> |
|
20 #include <hbtextitem.h> |
|
21 #include <hbaction.h> |
|
22 #include <hbpushbutton.h> |
|
23 #include <hbstyleloader.h> |
|
24 #include <hbabstractitemview.h> |
|
25 #include <hblistviewitem.h> |
|
26 |
|
27 #include "bubbleparticipantlistitem.h" |
|
28 #include "bubblemanagerif.h" |
|
29 #include "bubbleutils.h" |
|
30 |
|
31 BubbleParticipantListItem::BubbleParticipantListItem( |
|
32 QGraphicsItem *parent) : |
|
33 HbAbstractViewItem(parent), |
|
34 mText(0), |
|
35 mStatusIcon(0), |
|
36 mCipheringIcon(0), |
|
37 mExpandIcon(0), |
|
38 mButton1(0), |
|
39 mButton2(0), |
|
40 mExpanded(false) |
|
41 { |
|
42 HbStyleLoader::registerFilePath(":/bubbleparticipantlistitem.css"); |
|
43 HbStyleLoader::registerFilePath(":/bubbleparticipantlistitem.widgetml"); |
|
44 } |
|
45 |
|
46 BubbleParticipantListItem::~BubbleParticipantListItem() |
|
47 { |
|
48 } |
|
49 |
|
50 HbAbstractViewItem* BubbleParticipantListItem::createItem() |
|
51 { |
|
52 return new BubbleParticipantListItem(*this); |
|
53 } |
|
54 |
|
55 void BubbleParticipantListItem::updateChildItems() |
|
56 { |
|
57 HbAbstractViewItem::updateChildItems(); |
|
58 |
|
59 setFocusPolicy(Qt::ClickFocus); // to enable expanding |
|
60 |
|
61 // create primitives |
|
62 if (!mText) { |
|
63 mText = new HbTextItem(this); |
|
64 style()->setItemName( mText, "text" ); |
|
65 } |
|
66 |
|
67 if (!mCipheringIcon) { |
|
68 mCipheringIcon = new HbIconItem(this); |
|
69 style()->setItemName( mCipheringIcon, "ciphering" ); |
|
70 } |
|
71 |
|
72 if (!mStatusIcon) { |
|
73 mStatusIcon = new HbIconItem(this); |
|
74 style()->setItemName( mStatusIcon, "icon" ); |
|
75 } |
|
76 |
|
77 if (!mExpandIcon) { |
|
78 mExpandIcon = new HbIconItem(this); |
|
79 style()->setItemName( mExpandIcon, "expand-indi" ); |
|
80 |
|
81 // for expand/collapse controls |
|
82 if (itemView()) { |
|
83 connect( itemView()->selectionModel(), |
|
84 SIGNAL(currentChanged(QModelIndex,QModelIndex)), |
|
85 this, |
|
86 SLOT(currentIndexChanged(QModelIndex,QModelIndex)) ); |
|
87 } |
|
88 } |
|
89 |
|
90 BubbleParticipantListItem* p = |
|
91 static_cast<BubbleParticipantListItem*>(prototype()); |
|
92 |
|
93 if (mExpanded && !mButton1) { |
|
94 Q_ASSERT(p->mActions.count()==2); |
|
95 HbAction* action = p->mActions.at(0); |
|
96 mButton1 = new HbPushButton(this); |
|
97 mButton1->setIcon(action->icon()); |
|
98 style()->setItemName( mButton1, "button-1" ); |
|
99 |
|
100 // connect first action |
|
101 connect(mButton1, |
|
102 SIGNAL(clicked()), |
|
103 action, |
|
104 SLOT(trigger()), |
|
105 Qt::QueuedConnection); |
|
106 } else { |
|
107 delete mButton1; |
|
108 mButton1 = 0; |
|
109 } |
|
110 |
|
111 if (mExpanded && !mButton2) { |
|
112 Q_ASSERT(p->mActions.count()==2); |
|
113 HbAction* action = p->mActions.at(1); |
|
114 mButton2 = new HbPushButton(this); |
|
115 mButton2->setIcon(action->icon()); |
|
116 style()->setItemName( mButton2, "button-2" ); |
|
117 |
|
118 // connect second action |
|
119 connect(mButton2, |
|
120 SIGNAL(clicked()), |
|
121 action, |
|
122 SLOT(trigger()), |
|
123 Qt::QueuedConnection ); |
|
124 |
|
125 } else { |
|
126 delete mButton2; |
|
127 mButton2 = 0; |
|
128 } |
|
129 |
|
130 if (mText) { |
|
131 mText->setText(modelIndex().data(Qt::DisplayRole).toString()); |
|
132 } |
|
133 |
|
134 int state = (BubbleManagerIF::PhoneCallState) |
|
135 modelIndex().data(Qt::DecorationRole).toInt(); |
|
136 |
|
137 if (mStatusIcon) { |
|
138 BubbleUtils::setCallStatusIcon(state,0,*mStatusIcon); |
|
139 } |
|
140 |
|
141 if (mCipheringIcon) { |
|
142 int flags = !modelIndex().data(Qt::StatusTipRole).toBool() ? |
|
143 BubbleManagerIF::NoCiphering : 0; |
|
144 |
|
145 BubbleUtils::setCipheringIcon(state,flags,*mCipheringIcon); |
|
146 } |
|
147 |
|
148 if (mExpandIcon) { |
|
149 if (mExpanded) { |
|
150 mExpandIcon->setIcon(HbIcon("qtg_small_collapse")); |
|
151 } else { |
|
152 mExpandIcon->setIcon(HbIcon("qtg_small_expand")); |
|
153 } |
|
154 } |
|
155 |
|
156 repolish(); |
|
157 } |
|
158 |
|
159 void BubbleParticipantListItem::polish(HbStyleParameters& params) |
|
160 { |
|
161 if (mExpanded) { |
|
162 setProperty("layoutOption","expanded"); |
|
163 } else { |
|
164 setProperty("layoutOption","collapsed"); |
|
165 } |
|
166 |
|
167 HbAbstractViewItem::polish(params); |
|
168 } |
|
169 |
|
170 void BubbleParticipantListItem::setExpanded(bool expanded) |
|
171 { |
|
172 mExpanded = expanded; |
|
173 updateChildItems(); |
|
174 } |
|
175 |
|
176 void BubbleParticipantListItem::addAction(HbAction* action) |
|
177 { |
|
178 mActions.append(action); |
|
179 } |
|
180 |
|
181 void BubbleParticipantListItem::clearActions() |
|
182 { |
|
183 mActions.clear(); |
|
184 mExpanded = false; |
|
185 } |
|
186 |
|
187 void BubbleParticipantListItem::currentIndexChanged( |
|
188 const QModelIndex ¤t, |
|
189 const QModelIndex &previous) |
|
190 { |
|
191 Q_UNUSED(previous); |
|
192 |
|
193 if (modelIndex() == current) { |
|
194 if ( !mExpanded ) { |
|
195 setExpanded(true); |
|
196 } |
|
197 } else if (mExpanded) { |
|
198 setExpanded(false); |
|
199 } |
|
200 } |
|
201 |
|
202 int BubbleParticipantListItem::type() const |
|
203 { |
|
204 return HbListViewItem::Type; |
|
205 } |
|
206 |