|
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: HgWidgetDataModel implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QBrush> |
|
19 #include <HbIcon> |
|
20 #include <hgwidgets/hgwidgets.h> |
|
21 #include <QPainter> |
|
22 |
|
23 #include "locationpickertypes.h" |
|
24 #include "hgwidgetdatamodel.h" |
|
25 #include "locationpickerproxymodel.h" |
|
26 |
|
27 const int MAPSTROKE(3); |
|
28 // ---------------------------------------------------------------------------- |
|
29 // HgWidgetDataModel::HgWidgetDataModel() |
|
30 // ---------------------------------------------------------------------------- |
|
31 HgWidgetDataModel::HgWidgetDataModel( LocationPickerProxyModel *aProxyModel, QObject *aParent ) |
|
32 : QAbstractListModel(aParent), |
|
33 mImageType(ETypeHbIcon), |
|
34 mDefaultImage(KDummyImage), |
|
35 mUseLowResImages(false), |
|
36 mProxyModel(NULL) |
|
37 { |
|
38 mProxyModel = aProxyModel; |
|
39 |
|
40 } |
|
41 |
|
42 // ---------------------------------------------------------------------------- |
|
43 // HgWidgetDataModel::resetModel() |
|
44 // ---------------------------------------------------------------------------- |
|
45 void HgWidgetDataModel::resetModel( LocationPickerProxyModel *aProxyModel ) |
|
46 { |
|
47 //reset and update |
|
48 mProxyModel = aProxyModel; |
|
49 reset(); |
|
50 emit beginResetModel(); |
|
51 emit endResetModel(); |
|
52 } |
|
53 |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // HgWidgetDataModel::~HgWidgetDataModel() |
|
57 // ---------------------------------------------------------------------------- |
|
58 HgWidgetDataModel::~HgWidgetDataModel() |
|
59 { |
|
60 |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // HgWidgetDataModel::rowCount() |
|
65 // ---------------------------------------------------------------------------- |
|
66 int HgWidgetDataModel::rowCount( const QModelIndex &aParent ) const |
|
67 { |
|
68 Q_UNUSED(aParent); |
|
69 |
|
70 return mProxyModel->rowCount(QModelIndex()); |
|
71 |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------------------------- |
|
75 // HgWidgetDataModel::data() |
|
76 // ---------------------------------------------------------------------------- |
|
77 QVariant HgWidgetDataModel::data(const QModelIndex &aIndex, int aRole) const |
|
78 { |
|
79 Q_ASSERT(aIndex.row()>=0); |
|
80 int row= aIndex.row(); |
|
81 int col = aIndex.column(); |
|
82 //get proxy model index |
|
83 QModelIndex proxyModelIndex = mProxyModel->index(row,col); |
|
84 QVariant returnValue = QVariant(); |
|
85 if ( !aIndex.isValid() ) |
|
86 { |
|
87 return returnValue; |
|
88 } |
|
89 |
|
90 if( row >= mProxyModel->rowCount(QModelIndex()) ) |
|
91 { |
|
92 return returnValue; |
|
93 } |
|
94 |
|
95 switch ( aRole ) |
|
96 { |
|
97 case HgWidget::HgVisibilityRole: |
|
98 { |
|
99 returnValue = true; |
|
100 } |
|
101 break; |
|
102 case Qt::DisplayRole: |
|
103 { |
|
104 QStringList displayText; |
|
105 QString adressDetail = mProxyModel->data(proxyModelIndex,Qt::DisplayRole).toString(); |
|
106 QString text(""); |
|
107 displayText <<adressDetail<<text; |
|
108 returnValue = displayText; |
|
109 break; |
|
110 } |
|
111 case Qt::DecorationRole: |
|
112 { |
|
113 //get icon name from data model |
|
114 QString iconName = mProxyModel->data(proxyModelIndex,Qt::DecorationRole).toString(); |
|
115 if (iconName.isNull()) |
|
116 { |
|
117 returnValue = mDefaultImage; |
|
118 } |
|
119 else |
|
120 { |
|
121 QString adressType = mProxyModel->data(proxyModelIndex,Qt::UserRole+1).toString(); |
|
122 QPixmap mapPixmap(iconName); |
|
123 int mapWidth = mapPixmap.width(); |
|
124 int mapHeight = mapPixmap.height(); |
|
125 QBrush brush(Qt::black,Qt::SolidPattern); |
|
126 QPainter painter; |
|
127 painter.begin(&mapPixmap); |
|
128 HbIcon adressTypeIcon(adressType); |
|
129 //draw the adressType Icon over mapTile Icon |
|
130 QPixmap adressTypePixmap = adressTypeIcon.pixmap(); |
|
131 painter.drawPixmap( (mapPixmap.width()-adressTypePixmap.width()),0,adressTypePixmap ); |
|
132 painter.fillRect(QRect(0,0,mapWidth,MAPSTROKE),brush); |
|
133 painter.fillRect(QRect(0,mapHeight-MAPSTROKE,mapWidth,(mapHeight-MAPSTROKE)),brush); |
|
134 painter.fillRect(QRect(0,0,MAPSTROKE,mapPixmap.height()),brush); |
|
135 painter.fillRect(QRect((mapWidth-MAPSTROKE),0,mapWidth,mapHeight),brush); |
|
136 painter.end(); |
|
137 QIcon landscape( mapPixmap ); |
|
138 HbIcon landscapeIcon(landscape); |
|
139 returnValue = landscapeIcon; |
|
140 } |
|
141 break; |
|
142 } |
|
143 default: |
|
144 break; |
|
145 } |
|
146 |
|
147 return returnValue; |
|
148 } |
|
149 |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // HgWidgetDataModel::setImageDataType() |
|
153 // ---------------------------------------------------------------------------- |
|
154 void HgWidgetDataModel::setImageDataType(TImageType type) |
|
155 { |
|
156 mImageType = type; |
|
157 } |
|
158 |
|
159 |
|
160 |