|
1 /* |
|
2 * Copyright (c) 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 //Includes |
|
19 #include <QDebug> |
|
20 #include <hblabel.h> |
|
21 #include <QGraphicsLinearLayout> |
|
22 |
|
23 //User Includes |
|
24 #include "glxviewids.h" |
|
25 #include "glxmodelroles.h" //Contains the declaration of the roles used to retrieve the data from model |
|
26 #include "glxdetailstextedit.h" //Contains the declaration of the custom widget glxdetailstextedit |
|
27 #include "glxlocalisationstrings.h" //contains the localisation strings |
|
28 #include "glxdetailsviewmodelwrapper.h" //Contains the declaration of the modelwrapper |
|
29 #include "glxdetailsviewitemprototype.h" //contains the declaration of this file/class |
|
30 |
|
31 #define CONTENTMARGINS 5 |
|
32 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
33 //GlxDetailsViewItemProtoType |
|
34 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
35 GlxDetailsViewItemProtoType::GlxDetailsViewItemProtoType(QGraphicsItem* parent) : |
|
36 HbListViewItem(parent) |
|
37 { |
|
38 } |
|
39 |
|
40 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
41 //~GlxDetailsViewItemProtoType |
|
42 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
43 GlxDetailsViewItemProtoType::~GlxDetailsViewItemProtoType() |
|
44 { |
|
45 int widgetIndex = modelIndex().row(); |
|
46 switch (widgetIndex) { |
|
47 |
|
48 case widgetNameIndex: |
|
49 { |
|
50 delete mImageNameEditor; |
|
51 mImageNameEditor = NULL; |
|
52 break; |
|
53 } |
|
54 |
|
55 case widgetDateIndex: |
|
56 { |
|
57 delete mDateLabel; |
|
58 mDateLabel = NULL; |
|
59 break; |
|
60 } |
|
61 |
|
62 case widgetTimeIndex: |
|
63 { |
|
64 delete mDateLabel; |
|
65 mDateLabel = NULL; |
|
66 break; |
|
67 } |
|
68 |
|
69 case widgetSizeIndex: |
|
70 { |
|
71 delete mSizeLabel; |
|
72 mSizeLabel = NULL; |
|
73 break; |
|
74 } |
|
75 |
|
76 case widgetDescriptionIndex: |
|
77 { |
|
78 delete mDescriptionEditor; |
|
79 mDescriptionEditor = NULL; |
|
80 break; |
|
81 } |
|
82 |
|
83 default: |
|
84 break; |
|
85 } |
|
86 |
|
87 } |
|
88 |
|
89 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
90 //createItem |
|
91 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
92 HbAbstractViewItem* GlxDetailsViewItemProtoType::createItem() |
|
93 { |
|
94 return new GlxDetailsViewItemProtoType(*this); |
|
95 } |
|
96 |
|
97 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
98 //updateChildItems |
|
99 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
100 void GlxDetailsViewItemProtoType::updateChildItems() |
|
101 { |
|
102 |
|
103 switch (modelIndex().row()) { |
|
104 |
|
105 case widgetNameIndex: |
|
106 { |
|
107 //create the editor |
|
108 mImageNameEditor = new GlxDetailsTextEdit(this); |
|
109 mImageNameEditor->setMaxRows(1); |
|
110 |
|
111 //retrieve the name from the model |
|
112 QString nameString(GLX_DETAILS_NAME); |
|
113 QVariant nameData = modelIndex().data(GlxUriRole).toString(); |
|
114 if (nameData.isValid()) { |
|
115 if (nameData.canConvert<QString> ()) { |
|
116 nameString.append(nameData.toString()); |
|
117 } |
|
118 } |
|
119 mImageNameEditor->setItemText(nameString); |
|
120 |
|
121 //Get the sub state of the details view |
|
122 int substate = modelIndex().data(GlxSubStateRole).toInt(); |
|
123 if (substate != IMAGEVIEWER_DETAIL_S) { |
|
124 connect(mImageNameEditor, SIGNAL(editorTapped()), this, SLOT(forwardSignalsToView())); |
|
125 } |
|
126 else { |
|
127 mImageNameEditor->setTextItemReadOnly(TRUE); |
|
128 } |
|
129 |
|
130 //Connect the Signals |
|
131 const QAbstractItemModel *model = (modelIndex().model()); |
|
132 connect(model, SIGNAL(updateCustomWidgets()), this, SLOT(updateWidgetValues())); |
|
133 |
|
134 //Add the Layout |
|
135 QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); |
|
136 widgetLayout->setContentsMargins(CONTENTMARGINS,CONTENTMARGINS,CONTENTMARGINS,CONTENTMARGINS); |
|
137 widgetLayout->addItem(mImageNameEditor); |
|
138 setLayout(widgetLayout); |
|
139 break; |
|
140 } |
|
141 |
|
142 case widgetDateIndex: |
|
143 { |
|
144 //retrieve the date from the model |
|
145 QString dateString; |
|
146 QVariant dateData = modelIndex().data(GlxDateRole).toString(); |
|
147 if (dateData.isValid()) { |
|
148 if (dateData.canConvert<QString> ()) { |
|
149 dateString = dateData.toString(); |
|
150 } |
|
151 } |
|
152 |
|
153 //create the label and set the data |
|
154 mDateLabel = new HbLabel(this); |
|
155 mDateLabel->setPlainText(dateString); |
|
156 mDateLabel->setMinimumHeight(size().height() + 50); |
|
157 |
|
158 QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); |
|
159 widgetLayout->setContentsMargins(CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS); |
|
160 widgetLayout->addItem(mDateLabel); |
|
161 setLayout(widgetLayout); |
|
162 break; |
|
163 |
|
164 } |
|
165 case widgetTimeIndex: |
|
166 { |
|
167 //retrieve the time from the model |
|
168 QString timeString; |
|
169 QVariant timeData = modelIndex().data(GlxTimeRole).toString(); |
|
170 if (timeData.isValid()) { |
|
171 if (timeData.canConvert<QString> ()) { |
|
172 timeString = timeData.toString(); |
|
173 } |
|
174 } |
|
175 |
|
176 //create the label and set the data |
|
177 mTimeLabel = new HbLabel(this); |
|
178 mTimeLabel->setPlainText(timeString); |
|
179 mTimeLabel->setMinimumHeight(size().height() + 50); |
|
180 |
|
181 //Add the Layout |
|
182 QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); |
|
183 widgetLayout->setContentsMargins(CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS); |
|
184 widgetLayout->addItem(mTimeLabel); |
|
185 setLayout(widgetLayout); |
|
186 break; |
|
187 } |
|
188 |
|
189 case widgetSizeIndex: |
|
190 { |
|
191 //retrieve the size from the model |
|
192 QString sizeString; |
|
193 QVariant sizeData = modelIndex().data(GlxSizeRole).toString(); |
|
194 if (sizeData.isValid()) { |
|
195 if (sizeData.canConvert<QString> ()) { |
|
196 sizeString = sizeData.toString(); |
|
197 } |
|
198 } |
|
199 |
|
200 //create the label and set the data |
|
201 mSizeLabel = new HbLabel(this); |
|
202 mSizeLabel->setPlainText(sizeString); |
|
203 mSizeLabel->setMinimumHeight(size().height() + 50); |
|
204 |
|
205 //Add the Layout |
|
206 QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); |
|
207 widgetLayout->setContentsMargins(CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS); |
|
208 widgetLayout->addItem(mSizeLabel); |
|
209 setLayout(widgetLayout); |
|
210 break; |
|
211 } |
|
212 |
|
213 case widgetDescriptionIndex: |
|
214 { |
|
215 //create the editor |
|
216 mDescriptionEditor = new GlxDetailsTextEdit(this); |
|
217 mDescriptionEditor->setMaxRows(5); |
|
218 |
|
219 //retrieve the size from the model |
|
220 QString descString(GLX_DETAILS_DESCRIPTION); |
|
221 QVariant descData = modelIndex().data(GlxDescRole).toString(); |
|
222 if (descData.isValid()) { |
|
223 if (descData.canConvert<QString> ()) { |
|
224 descString.append(descData.toString()); |
|
225 } |
|
226 } |
|
227 mDescriptionEditor->setItemText(descString); |
|
228 |
|
229 //Get the sub state of the details view |
|
230 int substate = modelIndex().data(GlxSubStateRole).toInt(); |
|
231 if (substate != IMAGEVIEWER_DETAIL_S) { |
|
232 connect(mDescriptionEditor, SIGNAL(editorTapped()), this, SLOT(forwardSignalsToView())); |
|
233 } |
|
234 else { |
|
235 mDescriptionEditor->setTextItemReadOnly(TRUE); |
|
236 } |
|
237 |
|
238 //Connect the Signals |
|
239 const QAbstractItemModel *model = (modelIndex().model()); |
|
240 connect(model, SIGNAL(updateCustomWidgets()), this, SLOT(updateWidgetValues())); |
|
241 |
|
242 //Add the Layout |
|
243 QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); |
|
244 widgetLayout->setContentsMargins(CONTENTMARGINS,CONTENTMARGINS,CONTENTMARGINS,CONTENTMARGINS); |
|
245 widgetLayout->addItem(mDescriptionEditor); |
|
246 setLayout(widgetLayout); |
|
247 break; |
|
248 } |
|
249 |
|
250 default: |
|
251 break; |
|
252 } |
|
253 |
|
254 HbListViewItem::updateChildItems(); |
|
255 |
|
256 } |
|
257 |
|
258 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
259 //forwardSignalsToView |
|
260 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
261 void GlxDetailsViewItemProtoType::forwardSignalsToView() |
|
262 { |
|
263 int widgetIndex = modelIndex().row(); |
|
264 emit static_cast<GlxDetailsViewItemProtoType*> (prototype())->signalFromCustomWidget( |
|
265 widgetIndex); |
|
266 } |
|
267 |
|
268 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
269 //updateWidgetValues |
|
270 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
271 void GlxDetailsViewItemProtoType::updateWidgetValues() |
|
272 { |
|
273 int widgetIndex = modelIndex().row(); |
|
274 if (widgetIndex == GlxDetailsViewItemProtoType::widgetNameIndex) { |
|
275 |
|
276 QString nameString(GLX_DETAILS_NAME); |
|
277 QVariant nameData = modelIndex().data(GlxUriRole).toString(); |
|
278 |
|
279 if (nameData.isValid()) { |
|
280 if (nameData.canConvert<QString> ()) { |
|
281 nameString.append(nameData.toString()); |
|
282 } |
|
283 } |
|
284 mImageNameEditor->setItemText(nameString); |
|
285 } |
|
286 else { |
|
287 QString descString(GLX_DETAILS_DESCRIPTION); |
|
288 QVariant descData = modelIndex().data(GlxDescRole).toString(); |
|
289 |
|
290 if (descData.isValid()) { |
|
291 if (descData.canConvert<QString> ()) { |
|
292 descString.append(descData.toString()); |
|
293 } |
|
294 } |
|
295 mDescriptionEditor->setItemText(descString); |
|
296 } |
|
297 } |
|
298 |