|
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 "fbfilelistviewitem.h" |
|
19 |
|
20 #include <QString> |
|
21 #include <QStringList> |
|
22 #include <QGraphicsLinearLayout> |
|
23 #include <QRectF> |
|
24 #include <QPainter> |
|
25 |
|
26 #include <hblabel.h> |
|
27 #include <hbcheckbox.h> |
|
28 #include <hbabstractitemview.h> |
|
29 |
|
30 FbFileListViewItem::FbFileListViewItem(QGraphicsItem *parent) : |
|
31 HbListViewItem(parent), |
|
32 hLayout(0), |
|
33 mDiskNameLabel(0), |
|
34 mSizeLabel(0), |
|
35 mFreeLabel(0), |
|
36 mIconLabel(0) |
|
37 { |
|
38 } |
|
39 |
|
40 FbFileListViewItem::~FbFileListViewItem() |
|
41 { |
|
42 } |
|
43 |
|
44 void FbFileListViewItem::polish(HbStyleParameters ¶ms) |
|
45 { |
|
46 Q_UNUSED(params); |
|
47 } |
|
48 |
|
49 bool FbFileListViewItem::canSetModelIndex(const QModelIndex &index) const |
|
50 { |
|
51 Q_UNUSED(index); |
|
52 return true; |
|
53 } |
|
54 |
|
55 |
|
56 HbAbstractViewItem *FbFileListViewItem::createItem() |
|
57 { |
|
58 return new FbFileListViewItem(*this); |
|
59 } |
|
60 |
|
61 void FbFileListViewItem::updateChildItems() |
|
62 { |
|
63 if(!hLayout) { |
|
64 init(); |
|
65 } |
|
66 |
|
67 // Qt::DisplayRole |
|
68 QVariant displayRole = modelIndex().data(Qt::DisplayRole); |
|
69 QString diskName("default"); |
|
70 QStringList stringList; |
|
71 if (displayRole.isValid()) { |
|
72 if (displayRole.canConvert<QString>()) { // EFileViewModeSimple |
|
73 stringList.append(displayRole.toString()); |
|
74 } else if (displayRole.canConvert<QStringList>()) { // EFileViewModeExtended |
|
75 stringList = displayRole.toStringList(); |
|
76 } |
|
77 if (stringList.count() > 0) |
|
78 diskName = stringList[0]; //modelIndex().data( Qt::UserRole ).toString(); |
|
79 |
|
80 mDiskNameLabel->setPlainText(diskName/*displayString*/); |
|
81 } |
|
82 |
|
83 // mSizeLabel->setPlainText( hbTrId ( "Size: " ) /*+ FmUtils::formatStorageSize( driverInfo.size() )*/ ); |
|
84 // mFreeLabel->setPlainText( hbTrId ( "Free: " ) /*+ FmUtils::formatStorageSize( driverInfo.freeSize() )*/ ); |
|
85 if (stringList.count() > 1) |
|
86 mSizeLabel->setPlainText( stringList[1] ); |
|
87 |
|
88 //mStorageSizeDiagram->setFreeSizePercentage(); |
|
89 //mFreeLabel->setPlainText( stringList[2] ); |
|
90 |
|
91 // mCheckBox->setCheckState( checkState() ); |
|
92 |
|
93 // Qt::DecorationRole |
|
94 QVariant decorationRole = modelIndex().data(Qt::DecorationRole); |
|
95 if (decorationRole.isValid()) { |
|
96 QIcon icon = qvariant_cast<QIcon>(decorationRole); |
|
97 // if( icon.isNull() ) { |
|
98 // QFileIconProvider fileIconProvider; |
|
99 // icon = fileIconProvider.icon(QFileIconProvider::Drive); |
|
100 // } |
|
101 mIconLabel->setIcon(HbIcon(icon)); |
|
102 } |
|
103 } |
|
104 |
|
105 void FbFileListViewItem::setCheckedState(int state) |
|
106 { |
|
107 HbAbstractViewItem::setCheckState(static_cast<Qt::CheckState>(state)); |
|
108 } |
|
109 |
|
110 void FbFileListViewItem::init() |
|
111 { |
|
112 hLayout = new QGraphicsLinearLayout(); |
|
113 |
|
114 hLayout->setOrientation( Qt::Horizontal ); |
|
115 hLayout->addItem(layout()); |
|
116 |
|
117 mIconLabel = new HbLabel(); |
|
118 hLayout->addItem( mIconLabel ); |
|
119 hLayout->setAlignment( mIconLabel, Qt::AlignTop ); |
|
120 hLayout->setStretchFactor( mIconLabel, 0 ); |
|
121 |
|
122 // mStorageSizeDiagram = new FbDriveStorageSizeDiagram(this); |
|
123 // hLayout->addItem( mStorageSizeDiagram ); |
|
124 // hLayout->setAlignment( mIconLabel, Qt::AlignTop ); |
|
125 // hLayout->setStretchFactor( mStorageSizeDiagram, 0 ); |
|
126 |
|
127 QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout(); |
|
128 vLayout->setOrientation( Qt::Vertical ); |
|
129 |
|
130 mDiskNameLabel = new HbLabel(); |
|
131 //HbFontSpec fontSpecPrimary(HbFontSpec::Primary); |
|
132 //fontSpecPrimary.setTextHeight(18.0); |
|
133 //mDiskNameLabel->setFontSpec( fontSpecPrimary ); |
|
134 vLayout->addItem( mDiskNameLabel ); |
|
135 vLayout->setAlignment( mDiskNameLabel, Qt::AlignLeft ); |
|
136 |
|
137 mSizeLabel = new HbLabel(); |
|
138 //HbFontSpec fontSpecSecondary(HbFontSpec::Secondary); |
|
139 //fontSpecSecondary.setTextHeight(18.0); |
|
140 //mSizeLabel->setFontSpec(fontSpecSecondary); |
|
141 vLayout->addItem( mSizeLabel ); |
|
142 vLayout->setAlignment(mSizeLabel, Qt::AlignLeft); |
|
143 |
|
144 // mFreeLabel = new HbLabel(); |
|
145 // mFreeLabel->setFontSpec( HbFontSpec( HbFontSpec::Secondary ) ); |
|
146 // vLayout->addItem( mFreeLabel ); |
|
147 // vLayout->setAlignment( mFreeLabel, Qt::AlignLeft ); |
|
148 |
|
149 HbWidget *labelsWidget = new HbWidget(); |
|
150 labelsWidget->setLayout(vLayout); |
|
151 |
|
152 hLayout->setAlignment( labelsWidget, Qt::AlignLeft ); |
|
153 |
|
154 hLayout->addItem( labelsWidget ); |
|
155 hLayout->setStretchFactor( labelsWidget, 1 ); |
|
156 |
|
157 // this->setMaximumHeight(80); |
|
158 |
|
159 setLayout( hLayout ); |
|
160 } |