|
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 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
19 |
|
20 #include <QModelIndex> |
|
21 #include <QtDebug> |
|
22 #include <qdatetime.h> |
|
23 |
|
24 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
25 |
|
26 #include <hbdataform.h> |
|
27 #include <hblabel.h> |
|
28 #include <hbinstance.h> |
|
29 #include <hbiconitem.h> |
|
30 #include <hblineedit.h> |
|
31 #include <hbdataformmodel.h> |
|
32 #include <hbdataformmodelitem.h> |
|
33 #include <hbdataformviewitem.h> |
|
34 |
|
35 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
36 |
|
37 #include <glxmediamodel.h> |
|
38 #include "glxdetailsview.h" |
|
39 #include "glxmodelparm.h" |
|
40 #include "glxdetailscustomwidgets.h" |
|
41 #include "glxviewids.h" |
|
42 #include <glxcommandhandlers.hrh> |
|
43 |
|
44 |
|
45 |
|
46 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
47 //GlxDetailsView |
|
48 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
49 GlxDetailsView::GlxDetailsView(HbMainWindow *window) : GlxView ( GLX_DETAILSVIEW_ID), |
|
50 mDetailsPixmap(NULL), |
|
51 mBlackBackgroundItem(NULL), |
|
52 mModel(NULL), |
|
53 mWindow(window), |
|
54 mDataForm(NULL), |
|
55 mDetailModel(NULL), |
|
56 mCustomPrototype(NULL), |
|
57 mSelIndex (0) |
|
58 { |
|
59 qDebug("@@@GlxDetailsView::GlxDetailsView constructor Enter"); |
|
60 setContentFullScreen( true );//for smooth transtion between grid to full screen and vice versa |
|
61 } |
|
62 |
|
63 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
64 //~GlxDetailsView |
|
65 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
66 GlxDetailsView::~GlxDetailsView() |
|
67 { |
|
68 qDebug("@@@GlxDetailsView::~GlxDetailsView Enter"); |
|
69 |
|
70 if(mDetailsPixmap) { |
|
71 delete mDetailsPixmap; |
|
72 mDetailsPixmap = NULL; |
|
73 } |
|
74 |
|
75 if(mDataForm && mDataForm->model()) { |
|
76 delete mDataForm->model(); |
|
77 mDataForm->setModel(0); |
|
78 } |
|
79 |
|
80 if(mDataForm) { |
|
81 delete mDataForm; |
|
82 mDataForm = NULL; |
|
83 } |
|
84 |
|
85 |
|
86 if(mBlackBackgroundItem) { |
|
87 delete mBlackBackgroundItem; |
|
88 mBlackBackgroundItem = NULL; |
|
89 } |
|
90 |
|
91 clearCurrentModel(); |
|
92 disconnect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(updateLayout(Qt::Orientation))); |
|
93 } |
|
94 |
|
95 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
96 //activate |
|
97 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
98 void GlxDetailsView::activate() |
|
99 { |
|
100 qDebug("@@@GlxDetailsView::activate Enter"); |
|
101 setFormData(); |
|
102 connect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(updateLayout(Qt::Orientation))); |
|
103 } |
|
104 |
|
105 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
106 //initializeView |
|
107 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
108 void GlxDetailsView::initializeView(QAbstractItemModel *model) |
|
109 { |
|
110 qDebug("@@@GlxDetailsView::initializeView Enter"); |
|
111 |
|
112 mBlackBackgroundItem = new HbIconItem(this); |
|
113 mBlackBackgroundItem->setBrush(QBrush(Qt::black)); |
|
114 mBlackBackgroundItem->hide(); |
|
115 |
|
116 //To show the thumbnail |
|
117 mDetailsPixmap = new QGraphicsPixmapItem(this); |
|
118 |
|
119 //Create the form and the model for the data form |
|
120 mDataForm = new HbDataForm(this); |
|
121 mDetailModel = new HbDataFormModel(); |
|
122 |
|
123 //custom prototype |
|
124 mCustomPrototype = new GlxDetailsCustomWidgets(mDataForm); |
|
125 mDataForm->setItemPrototype(mCustomPrototype); |
|
126 |
|
127 //Set the Model |
|
128 mModel = model; |
|
129 initializeNewModel(); |
|
130 |
|
131 //Add the Widgets according to the mime type |
|
132 addWidgets(); |
|
133 |
|
134 //Set the Layout Correspondingly. |
|
135 updateLayout(mWindow->orientation()); |
|
136 |
|
137 //Shows the Image |
|
138 showImage(); |
|
139 |
|
140 } |
|
141 |
|
142 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
143 //resetView |
|
144 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
145 void GlxDetailsView::resetView() |
|
146 { |
|
147 //Do Nothing here |
|
148 } |
|
149 |
|
150 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
151 //deActivate |
|
152 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
153 void GlxDetailsView::deActivate() |
|
154 { |
|
155 qDebug("@@@GlxDetailsView::deActivate Enter"); |
|
156 |
|
157 //mWindow->setItemVisible(Hb::AllItems, FALSE) ; |
|
158 |
|
159 if(mDetailsPixmap) { |
|
160 delete mDetailsPixmap; |
|
161 mDetailsPixmap = NULL; |
|
162 } |
|
163 |
|
164 if(mDataForm && mDataForm->model()) { |
|
165 delete mDataForm->model(); |
|
166 mDataForm->setModel(0); |
|
167 } |
|
168 |
|
169 if(mDataForm) { |
|
170 delete mDataForm; |
|
171 mDataForm = NULL; |
|
172 } |
|
173 |
|
174 if(mBlackBackgroundItem) { |
|
175 delete mBlackBackgroundItem; |
|
176 mBlackBackgroundItem = NULL; |
|
177 } |
|
178 |
|
179 clearCurrentModel(); |
|
180 disconnect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(updateLayout(Qt::Orientation))); |
|
181 } |
|
182 |
|
183 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
184 //addWidgets |
|
185 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
186 void GlxDetailsView::addWidgets() |
|
187 { |
|
188 qDebug("@@@GlxDetailsView::addWidgets create the form"); |
|
189 |
|
190 //----------------------------START OF CREATION OF WIDGETS---------------------------------// |
|
191 // To add new widgets in the details view, add it here. |
|
192 |
|
193 //---------------------------IMAGE NAME LABEL --------------------------------------------// |
|
194 qDebug("@@@GlxDetailsView::addWidgets create Image name Label"); |
|
195 HbDataFormModelItem *imageLabelitem = mDetailModel->appendDataFormItem((HbDataFormModelItem::DataItemType)(ImageNameItem), QString("Name"), mDetailModel->invisibleRootItem()); |
|
196 imageLabelitem->setData(HbDataFormModelItem::KeyRole,QString("")); |
|
197 |
|
198 //---------------------------DATE LABEL --------------------------------------------// |
|
199 qDebug("@@@GlxDetailsView::addWidgets create Image name Label"); |
|
200 HbDataFormModelItem *dateLabelItem = mDetailModel->appendDataFormItem((HbDataFormModelItem::DataItemType)(DateLabelItem), QString("Date"), mDetailModel->invisibleRootItem()); |
|
201 dateLabelItem->setData(HbDataFormModelItem::KeyRole,QString("")); |
|
202 |
|
203 //---------------------------LOCATION LABEL--------------------------------------------// |
|
204 qDebug("@@@GlxDetailsView::addWidgets create Location Label"); |
|
205 HbDataFormModelItem *locationLabelItem = mDetailModel->appendDataFormItem((HbDataFormModelItem::DataItemType)(LocationTagItem), QString("Location Tag"), mDetailModel->invisibleRootItem()); |
|
206 locationLabelItem->setData(HbDataFormModelItem::KeyRole, QString("")); |
|
207 |
|
208 //---------------------------DURATION LABEL--------------------------------------------// |
|
209 /* |
|
210 Need to Add a check here for the type of the item, if it is video or image |
|
211 qDebug("@@@GlxDetailsView::addWidgets create Duration Label"); |
|
212 HbDataFormModelItem *DurationLabelItem = mDetailModel->appendDataFormItem((HbDataFormModelItem::DataItemType)(DurationItem), QString("Duration"), mDetailModel->invisibleRootItem()); |
|
213 DurationLabelItem->setData(HbDataFormModelItem::KeyRole, QString("")); |
|
214 */ |
|
215 |
|
216 //----------------------------COMMENTS TEXT ITEM---------------------------------------------// |
|
217 qDebug("@@@GlxDetailsView::addWidgets create Comment text edit"); |
|
218 HbDataFormModelItem *commentsLabelItem = mDetailModel->appendDataFormItem((HbDataFormModelItem::DataItemType)(CommentsItem), QString("Comments"), mDetailModel->invisibleRootItem()); |
|
219 commentsLabelItem->setData(HbDataFormModelItem::KeyRole, QString("")); |
|
220 |
|
221 //----------------------------END OF CREATION OF WIDGETS-------------------------------------// |
|
222 |
|
223 //Set the model to the Data Form |
|
224 mDataForm->setModel(mDetailModel); |
|
225 } |
|
226 |
|
227 |
|
228 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
229 //setModel |
|
230 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
231 void GlxDetailsView::setModel(QAbstractItemModel *model) |
|
232 { |
|
233 qDebug("@@@GlxDetailsView::setModel"); |
|
234 if ( mModel == model ) { |
|
235 return ; |
|
236 } |
|
237 clearCurrentModel(); |
|
238 mModel = model; |
|
239 initializeNewModel(); |
|
240 } |
|
241 |
|
242 QGraphicsItem * GlxDetailsView::getAnimationItem(GlxEffect transtionEffect) |
|
243 { |
|
244 if ( transtionEffect == FULLSCREEN_TO_DETAIL |
|
245 || transtionEffect == DETAIL_TO_FULLSCREEN ) { |
|
246 return this; |
|
247 } |
|
248 |
|
249 return NULL; |
|
250 } |
|
251 |
|
252 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
253 //updateLayout |
|
254 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
255 void GlxDetailsView::updateLayout(Qt::Orientation orient) |
|
256 { |
|
257 qDebug("GlxDetailsView::updateLayout() %d", orient ); |
|
258 |
|
259 QRect screen_rect = mWindow->geometry(); |
|
260 setGeometry(screen_rect); |
|
261 |
|
262 if(orient == Qt::Horizontal) |
|
263 { |
|
264 qDebug("GlxDetailsView::updateLayout HORIZONTAL"); |
|
265 |
|
266 mBlackBackgroundItem->setSize(QSize(280,280)); |
|
267 mBlackBackgroundItem->setPos(11,71); |
|
268 |
|
269 mDetailsPixmap->setPos(15,75); |
|
270 mDetailsPixmap->setZValue(mBlackBackgroundItem->zValue() + 1); |
|
271 |
|
272 // mDataForm->setPos(301,5); |
|
273 mDataForm->setGeometry(301,60,335,300); |
|
274 |
|
275 } |
|
276 else |
|
277 { |
|
278 qDebug("GlxDetailsView::updateLayout VERTICAL"); |
|
279 |
|
280 mBlackBackgroundItem->setSize(QSize(310,260)); |
|
281 mBlackBackgroundItem->setPos(25,75); |
|
282 |
|
283 mDetailsPixmap->setPos(25,75); |
|
284 mDetailsPixmap->setZValue(mBlackBackgroundItem->zValue() + 1); |
|
285 |
|
286 // mDataForm->setPos(5,291); |
|
287 mDataForm->setGeometry(5,351,335,300); |
|
288 mDataForm->setMaximumWidth(340); |
|
289 } |
|
290 } |
|
291 |
|
292 void GlxDetailsView::rowsRemoved(const QModelIndex &parent, int start, int end) |
|
293 { |
|
294 Q_UNUSED(parent); |
|
295 Q_UNUSED(start); |
|
296 Q_UNUSED(end); |
|
297 qDebug("GlxDetailsView::rowsRemoved"); |
|
298 |
|
299 if ( mModel->rowCount() <= 0 ) { |
|
300 return emit actionTriggered( EGlxCmdEmptyData ); |
|
301 } |
|
302 |
|
303 if ( start <= mSelIndex && end >= mSelIndex ) { |
|
304 return emit actionTriggered( EGlxCmdBack ); |
|
305 } |
|
306 } |
|
307 |
|
308 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
309 //showImage |
|
310 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
311 void GlxDetailsView::showImage() |
|
312 { |
|
313 qDebug("GlxDetailsView::showImage() Enter" ); |
|
314 |
|
315 QVariant variant = mModel->data( mModel->index(0,0), GlxFocusIndexRole ); |
|
316 if ( variant.isValid() && variant.canConvert<int> () ) { |
|
317 mSelIndex = variant.value<int>(); |
|
318 } |
|
319 |
|
320 variant = mModel->data( mModel->index( mSelIndex ,0), GlxFsImageRole); |
|
321 if ( variant.isValid() && variant.canConvert<HbIcon> () ) |
|
322 { |
|
323 QIcon itemIcon = variant.value<HbIcon>().qicon(); |
|
324 if(mWindow->orientation() == Qt::Horizontal) |
|
325 { |
|
326 qDebug("GlxDetailsView::showImage HORIZONTAL"); |
|
327 QPixmap itemPixmap = itemIcon.pixmap(128,128); |
|
328 QSize sz( 270, 270); |
|
329 itemPixmap = itemPixmap.scaled(sz, Qt::IgnoreAspectRatio ); |
|
330 if(itemPixmap.isNull()) |
|
331 { |
|
332 qDebug("@@@GlxDetailsView::showImage Null Pixmap"); |
|
333 } |
|
334 else |
|
335 { |
|
336 qDebug("@@@GlxDetailsView::showImage NOT --Null Pixmap"); |
|
337 mDetailsPixmap->setPixmap(itemPixmap); |
|
338 } |
|
339 } |
|
340 else |
|
341 { |
|
342 qDebug("GlxDetailsView::showImage VERTICAL"); |
|
343 |
|
344 QPixmap itemPixmap = itemIcon.pixmap(128,128); |
|
345 QSize sz( 310, 260); |
|
346 itemPixmap = itemPixmap.scaled(sz, Qt::IgnoreAspectRatio ); |
|
347 |
|
348 if(itemPixmap.isNull()) |
|
349 { |
|
350 qDebug("@@@GlxDetailsView::showImage Null Pixmap"); |
|
351 } |
|
352 else |
|
353 { |
|
354 qDebug("@@@GlxDetailsView::showImage NOT --Null Pixmap"); |
|
355 mDetailsPixmap->setPixmap(itemPixmap); |
|
356 } |
|
357 } |
|
358 } |
|
359 } |
|
360 |
|
361 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
362 //FillData |
|
363 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
364 void GlxDetailsView::setFormData() |
|
365 { |
|
366 qDebug("GlxDetailsView::FillData Enter"); |
|
367 //Call to set the Image Name |
|
368 setImageName(); |
|
369 //Call to set the date in the from |
|
370 setDate(); |
|
371 } |
|
372 |
|
373 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
374 //setImageName |
|
375 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
376 void GlxDetailsView::setImageName() |
|
377 { |
|
378 qDebug("GlxDetailsView::setImageName Enter"); |
|
379 |
|
380 QString imagePath = (mModel->data(mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>(),0),GlxUriRole)).value<QString>(); |
|
381 QString imageName = imagePath.section('\\',-1); |
|
382 |
|
383 //Fetch the text edit for displaying the Name from the Form Model |
|
384 GlxDetailsCustomWidgets * imageLabel = (GlxDetailsCustomWidgets *)mDataForm->itemByIndex(mDetailModel->index(0,0)); |
|
385 |
|
386 if(imageLabel) |
|
387 { |
|
388 qDebug("GlxDetailsView::setImageName imageLabel!=NULL"); |
|
389 HbLineEdit* label = static_cast<HbLineEdit*>(imageLabel->dataItemContentWidget()); |
|
390 |
|
391 if(label) |
|
392 { |
|
393 qDebug("GlxDetailsView::setImageName,setText"); |
|
394 label->setText(imageName); |
|
395 } |
|
396 } |
|
397 } |
|
398 |
|
399 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
400 //setDate |
|
401 //-------------------------------------------------------------------------------------------------------------------------------------------- |
|
402 void GlxDetailsView::setDate() |
|
403 { |
|
404 qDebug("GlxDetailsView::setDate Enter"); |
|
405 |
|
406 QString datestring; |
|
407 QString str("dd.MM.yyyy"); |
|
408 QDate date = (mModel->data(mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>(),0),GlxDateRole)).value<QDate>(); |
|
409 |
|
410 if(date.isNull() == FALSE ) |
|
411 { |
|
412 qDebug("GlxDetailsView::setDate date is not Null"); |
|
413 datestring = date.toString(str); |
|
414 } |
|
415 |
|
416 //Fetch the Label from the Form Model |
|
417 GlxDetailsCustomWidgets * dateLabel = (GlxDetailsCustomWidgets *)mDataForm->itemByIndex(mDetailModel->index(1,0)); |
|
418 |
|
419 if(dateLabel) |
|
420 { |
|
421 qDebug("GlxDetailsView::setDate dateLabel!=NULL"); |
|
422 HbLabel* label = static_cast<HbLabel*>(dateLabel->dataItemContentWidget()); |
|
423 |
|
424 if(label) |
|
425 { |
|
426 qDebug("GlxDetailsView::setDate,setText"); |
|
427 label->setPlainText(datestring); |
|
428 } |
|
429 } |
|
430 } |
|
431 |
|
432 void GlxDetailsView::initializeNewModel() |
|
433 { |
|
434 if ( mModel ) { |
|
435 connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved(QModelIndex,int,int))); |
|
436 } |
|
437 } |
|
438 |
|
439 void GlxDetailsView::clearCurrentModel() |
|
440 { |
|
441 if ( mModel ) { |
|
442 disconnect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved(QModelIndex,int,int))); |
|
443 mModel = NULL ; |
|
444 } |
|
445 } |