bluetoothengine/btui/btcpplugin/btcpuisearchlistviewitem.cpp
branchRCL_3
changeset 23 9386f31cc85b
parent 22 613943a21004
child 24 269724087bed
equal deleted inserted replaced
22:613943a21004 23:9386f31cc85b
     1 /*
       
     2 * Copyright (c) 2010 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 "btcpuisearchlistviewitem.h"
       
    20 #include "btdevicemodel.h"
       
    21 #include "btuiiconutil.h"
       
    22 #include <QGraphicsGridLayout>
       
    23 
       
    24 BtCpUiSearchListViewItem::BtCpUiSearchListViewItem(QGraphicsItem * parent) :
       
    25     HbListViewItem(parent), mParent(parent)
       
    26 {
       
    27     mDeviceNameLabel = 0;
       
    28     mDevTypeIconLabel = 0;
       
    29     mDevTypeTextLabel = 0;
       
    30     mBtuiModelSortFilter = ((BtCpUiSearchListViewItem *)parent)->mBtuiModelSortFilter;
       
    31     
       
    32     mRow = 0;   
       
    33 }
       
    34 
       
    35 BtCpUiSearchListViewItem::~BtCpUiSearchListViewItem()
       
    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 * BtCpUiSearchListViewItem::createItem()
       
    48 {
       
    49     return new BtCpUiSearchListViewItem(*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 BtCpUiSearchListViewItem::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 
       
    69     // create new icon label if needed
       
    70     if (!mDevTypeIconLabel) {
       
    71         mDevTypeIconLabel = new HbLabel();
       
    72         mDevTypeIconLabel->setPreferredSize(53.5260, 53.5260); //8un x 8un
       
    73         mDevTypeIconLabel->setMinimumWidth(53.5260);
       
    74     }
       
    75     // create new label if needed
       
    76     if (!mDeviceNameLabel) {
       
    77         mDeviceNameLabel = new HbLabel();
       
    78         mDeviceNameLabel->setPreferredSize(250, 26.763);
       
    79     }
       
    80     // create new label if needed
       
    81     if (!mDevTypeTextLabel) {
       
    82         mDevTypeTextLabel = new HbLabel();
       
    83         mDevTypeTextLabel->setPreferredSize(250, 26.763);
       
    84     }
       
    85     // create layout if needed
       
    86     if ( !mRow ) {
       
    87         // Still need to create the actual layout
       
    88         mRow = new QGraphicsGridLayout();
       
    89         mRow->addItem(mDevTypeIconLabel,0,0,2,1);
       
    90         mRow->addItem(mDeviceNameLabel,0,1,1,1);
       
    91         mRow->addItem(mDevTypeTextLabel,1,1,1,1);
       
    92         setLayout(mRow);
       
    93     }
       
    94         
       
    95     QString data = index.data(Qt::DisplayRole).toString();
       
    96     int cod = (index.data(BtDeviceModel::CoDRole)).toInt();
       
    97     int majorProperty = (index.data(BtDeviceModel::MajorPropertyRole)).toInt();
       
    98     
       
    99     // ToDo:  remove clear() once Orbit bug is fixed
       
   100     mDeviceNameLabel->clear();
       
   101     mDeviceNameLabel->setPlainText(data);
       
   102     mDevTypeIconLabel->clear();
       
   103     mDevTypeTextLabel->clear();
       
   104     mDevTypeTextLabel->setPlainText( getDeviceTypeString( cod ));
       
   105     HbIcon icon = 
       
   106     getBadgedDeviceTypeIcon(cod, majorProperty,
       
   107             BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight );
       
   108     mDevTypeIconLabel->setIcon(icon);
       
   109 }
       
   110 
       
   111 
       
   112 void BtCpUiSearchListViewItem::setModelSortFilter(BtuiModelSortFilter *filter)
       
   113 {
       
   114     mBtuiModelSortFilter = filter;
       
   115 }