1 /* |
|
2 * Copyright (c) 2008-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: BTUISearchListViewItem implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "btcpuimainlistviewitem.h" |
|
20 #include "btdevicemodel.h" |
|
21 #include "btuiiconutil.h" |
|
22 #include <QGraphicsGridLayout> |
|
23 |
|
24 BtCpUiMainListViewItem::BtCpUiMainListViewItem(QGraphicsItem * parent) : |
|
25 HbListViewItem(parent), mParent(parent) |
|
26 { |
|
27 mDeviceNameLabel = 0; |
|
28 mDevTypeIconLabel = 0; |
|
29 mDevTypeTextLabel = 0; |
|
30 mBtuiModelSortFilter = ((BtCpUiMainListViewItem *)parent)->mBtuiModelSortFilter; |
|
31 |
|
32 mRow = 0; |
|
33 } |
|
34 |
|
35 BtCpUiMainListViewItem::~BtCpUiMainListViewItem() |
|
36 { |
|
37 // delete mDeviceNameLabel; |
|
38 // delete mDevTypeIconLabel; |
|
39 // delete mDevTypeTextLabel; |
|
40 } |
|
41 |
|
42 /* |
|
43 * This method is called by the HbListView when it needs a new |
|
44 * view item element. |
|
45 * |
|
46 */ |
|
47 HbAbstractViewItem * BtCpUiMainListViewItem::createItem() |
|
48 { |
|
49 return new BtCpUiMainListViewItem(*this); |
|
50 } |
|
51 |
|
52 /*! |
|
53 UpdateChildItem updates the item graphics. |
|
54 Screen elements are created once if not already done. This may increase the overall memory |
|
55 consumption of the application, however, this is deemed inconsequential. There might be a small |
|
56 performance improvement with current style. |
|
57 */ |
|
58 void BtCpUiMainListViewItem::updateChildItems() |
|
59 { |
|
60 QModelIndex index; |
|
61 |
|
62 // Get device name from model |
|
63 if (mBtuiModelSortFilter) |
|
64 index = mBtuiModelSortFilter->mapToSource(modelIndex()); |
|
65 else |
|
66 index = modelIndex(); |
|
67 |
|
68 // create new icon label if needed |
|
69 if (!mDevTypeIconLabel) { |
|
70 mDevTypeIconLabel = new HbLabel(); |
|
71 mDevTypeIconLabel->setPreferredSize(53.5260, 53.5260); //8un x 8un |
|
72 mDevTypeIconLabel->setMinimumWidth(53.5260); |
|
73 } |
|
74 // create new label if needed |
|
75 if (!mDeviceNameLabel) { |
|
76 mDeviceNameLabel = new HbLabel(); |
|
77 mDeviceNameLabel->setPreferredSize(250, 26.763); |
|
78 } |
|
79 // create new label if needed |
|
80 if (!mDevTypeTextLabel) { |
|
81 mDevTypeTextLabel = new HbLabel(); |
|
82 mDevTypeTextLabel->setPreferredSize(250, 26.763); |
|
83 } |
|
84 // create layout if needed |
|
85 if ( !mRow ) { |
|
86 // Still need to create the actual layout |
|
87 mRow = new QGraphicsGridLayout(); |
|
88 mRow->addItem(mDevTypeIconLabel,0,0,2,1); |
|
89 mRow->addItem(mDeviceNameLabel,0,1,1,1); |
|
90 mRow->addItem(mDevTypeTextLabel,1,1,1,1); |
|
91 setLayout(mRow); |
|
92 } |
|
93 |
|
94 QString data = index.data(Qt::DisplayRole).toString(); |
|
95 int cod = (index.data(BtDeviceModel::CoDRole)).toInt(); |
|
96 int majorProperty = (index.data(BtDeviceModel::MajorPropertyRole)).toInt(); |
|
97 |
|
98 // ToDo: remove clear() once Orbit bug is fixed |
|
99 mDeviceNameLabel->clear(); |
|
100 mDeviceNameLabel->setPlainText(data); |
|
101 mDevTypeIconLabel->clear(); |
|
102 mDevTypeTextLabel->clear(); |
|
103 mDevTypeTextLabel->setPlainText( getDeviceTypeString( cod )); |
|
104 HbIcon icon = |
|
105 getBadgedDeviceTypeIcon( cod, majorProperty, |
|
106 BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight ); |
|
107 mDevTypeIconLabel->setIcon(icon); |
|
108 } |
|
109 |
|
110 |
|
111 void BtCpUiMainListViewItem::setModelSortFilter(BtuiModelSortFilter *filter) |
|
112 { |
|
113 mBtuiModelSortFilter = filter; |
|
114 } |
|