filebrowser/ui/src/fbdrivelistviewitem.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "fbdrivelistviewitem.h"
       
    19 #include "driveentry.h"
       
    20 #include "fbdrivemodel.h"
       
    21 
       
    22 #include <hblabel.h>
       
    23 #include <hbcheckbox.h>
       
    24 #include <hbabstractitemview.h>
       
    25 
       
    26 #include <QString>
       
    27 #include <QStringList>
       
    28 #include <QFileIconProvider>
       
    29 #include <QGraphicsLinearLayout>
       
    30 #include <QRectF>
       
    31 #include <QPainter>
       
    32 
       
    33 FbDriveListViewItem::FbDriveListViewItem(QGraphicsItem *parent) :
       
    34     HbListViewItem(parent),
       
    35     hLayout(0),
       
    36     mDiskNameLabel(0),
       
    37     mSizeLabel(0),
       
    38     mFreeLabel(0),
       
    39     mIconLabel(0)
       
    40 {
       
    41 }
       
    42 
       
    43 FbDriveListViewItem::~FbDriveListViewItem()
       
    44 {
       
    45 }
       
    46 
       
    47 void FbDriveListViewItem::polish(HbStyleParameters& params)
       
    48 {
       
    49     Q_UNUSED(params);
       
    50 }
       
    51 
       
    52 bool FbDriveListViewItem::canSetModelIndex(const QModelIndex &index) const
       
    53 {
       
    54     Q_UNUSED(index);
       
    55     return true;
       
    56 }
       
    57 
       
    58 
       
    59 HbAbstractViewItem *FbDriveListViewItem::createItem()
       
    60 {
       
    61     return new FbDriveListViewItem(*this);
       
    62 }
       
    63 
       
    64 void FbDriveListViewItem::updateChildItems()
       
    65 {
       
    66     if(!hLayout) {
       
    67         init();
       
    68     }
       
    69 
       
    70     // Qt::DisplayRole
       
    71 //    QVariant displayRole = modelIndex().data(Qt::DisplayRole);
       
    72 //    QString diskName("default");
       
    73     QStringList stringList;
       
    74 //    if (displayRole.isValid()) {
       
    75 //        if (displayRole.canConvert<QString>()) {                // EFileViewModeSimple
       
    76 //            stringList.append(displayRole.toString());
       
    77 //        } else if (displayRole.canConvert<QStringList>()) {     // EFileViewModeExtended
       
    78 //            stringList = displayRole.toStringList();
       
    79 //        }
       
    80 //        if (stringList.count() > 0)
       
    81 //            diskName = stringList[0]; //modelIndex().data( Qt::UserRole ).toString();
       
    82 //
       
    83 //        mDiskNameLabel->setPlainText(diskName/*displayString*/);
       
    84 //    }
       
    85 //    if (stringList.count() > 1)
       
    86 //        mSizeLabel->setPlainText( stringList[1] );
       
    87 
       
    88 
       
    89     // Get the Drive Entry
       
    90     const FbDriveModel* driveModel= qobject_cast<const FbDriveModel *>(modelIndex().model());
       
    91     DriveEntry driveEntry = driveModel->driveEntry(modelIndex());
       
    92 
       
    93     const QString SimpleDriveEntry("%1: <%2>");
       
    94 
       
    95     QString diskName = SimpleDriveEntry.arg(driveEntry.driveLetter()).arg(driveEntry.mediaTypeString());
       
    96     mDiskNameLabel->setPlainText(diskName);
       
    97 
       
    98     const QString ExtendedDriveEntry("%1/%2 kB");
       
    99     QString diskSize = ExtendedDriveEntry.arg(QString::number(driveEntry.volumeInfoFree()/1024))
       
   100                                          .arg(QString::number(driveEntry.volumeInfoSize()/1024));
       
   101     mSizeLabel->setPlainText( diskSize );
       
   102 
       
   103     //mFreeLabel->setPlainText( stringList[2] );
       
   104 
       
   105     //    mCheckBox->setCheckState( checkState() );
       
   106 
       
   107     // Qt::DecorationRole
       
   108     // QTBUG-11033 No Icon provided for QFileIconProvider::Desktop, Network, Drive on Symbian
       
   109     QVariant decorationRole = modelIndex().data(Qt::DecorationRole);
       
   110     if (decorationRole.isValid()) {
       
   111         QIcon icon = qvariant_cast<QIcon>(decorationRole);
       
   112     if( icon.isNull() ) {
       
   113         QFileIconProvider fileIconProvider;
       
   114         icon = fileIconProvider.icon(QFileIconProvider::File);
       
   115     }
       
   116     mIconLabel->setIcon(HbIcon(icon));
       
   117     }
       
   118 }
       
   119 
       
   120 void FbDriveListViewItem::setCheckedState(int state)
       
   121 {
       
   122     HbAbstractViewItem::setCheckState(static_cast<Qt::CheckState>(state));
       
   123 }
       
   124 
       
   125 void FbDriveListViewItem::init()
       
   126 {
       
   127     hLayout = new QGraphicsLinearLayout();
       
   128     hLayout->setContentsMargins(0, 0, 0, 0);
       
   129 
       
   130     hLayout->setOrientation( Qt::Horizontal );
       
   131     hLayout->addItem(layout());
       
   132 
       
   133     mIconLabel = new HbLabel();
       
   134     hLayout->addItem( mIconLabel );
       
   135     hLayout->setAlignment( mIconLabel, Qt::AlignTop );
       
   136     hLayout->setStretchFactor( mIconLabel, 0 );
       
   137 
       
   138     QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout();
       
   139     //vLayout->setContentsMargins(0, 0, 0, 0);
       
   140     vLayout->setOrientation( Qt::Vertical );
       
   141 
       
   142     mDiskNameLabel = new HbLabel();
       
   143     HbFontSpec fontSpecPrimary(HbFontSpec::Primary);
       
   144     //fontSpecPrimary.setTextHeight(18.0);
       
   145     mDiskNameLabel->setFontSpec( fontSpecPrimary );
       
   146     vLayout->addItem( mDiskNameLabel );
       
   147     vLayout->setAlignment( mDiskNameLabel, Qt::AlignLeft );
       
   148 
       
   149     mSizeLabel = new HbLabel();
       
   150     HbFontSpec fontSpecSecondary(HbFontSpec::Secondary);
       
   151     //fontSpecSecondary.setTextHeight(18.0);
       
   152     mSizeLabel->setFontSpec(fontSpecSecondary);
       
   153     vLayout->addItem( mSizeLabel );
       
   154     vLayout->setAlignment(mSizeLabel, Qt::AlignLeft);
       
   155 
       
   156 //    mFreeLabel = new HbLabel();
       
   157 //    mFreeLabel->setFontSpec( HbFontSpec( HbFontSpec::Secondary ) );
       
   158 //    vLayout->addItem( mFreeLabel );
       
   159 //    vLayout->setAlignment( mFreeLabel, Qt::AlignLeft );
       
   160 
       
   161     HbWidget *labelsWidget = new HbWidget();
       
   162     labelsWidget->setLayout(vLayout);
       
   163 
       
   164     hLayout->setAlignment( labelsWidget, Qt::AlignLeft );
       
   165 
       
   166     hLayout->addItem( labelsWidget );
       
   167     hLayout->setStretchFactor( labelsWidget, 1 );
       
   168 
       
   169     //this->setMaximumHeight( mDiskNameLabel->preferredHeight() );
       
   170     //setMaximumHeight( mIconLabel->preferredHeight() );
       
   171 
       
   172     setLayout( hLayout );
       
   173 }