diff -r 743eb0b9959e -r 199e6e1e0b54 ui/views/detailsview/src/glxdetailsviewitemprototype.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/views/detailsview/src/glxdetailsviewitemprototype.cpp Fri Sep 17 08:29:24 2010 +0300 @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: ?Description + * + */ + +//Includes +#include +#include +#include + +//User Includes +#include "glxviewids.h" +#include "glxmodelroles.h" //Contains the declaration of the roles used to retrieve the data from model +#include "glxdetailstextedit.h" //Contains the declaration of the custom widget glxdetailstextedit +#include "glxlocalisationstrings.h" //contains the localisation strings +#include "glxdetailsviewmodelwrapper.h" //Contains the declaration of the modelwrapper +#include "glxdetailsviewitemprototype.h" //contains the declaration of this file/class + +#define CONTENTMARGINS 5 +//-------------------------------------------------------------------------------------------------------------------------------------------- +//GlxDetailsViewItemProtoType +//-------------------------------------------------------------------------------------------------------------------------------------------- +GlxDetailsViewItemProtoType::GlxDetailsViewItemProtoType(QGraphicsItem* parent) : + HbListViewItem(parent) +{ +} + +//-------------------------------------------------------------------------------------------------------------------------------------------- +//~GlxDetailsViewItemProtoType +//-------------------------------------------------------------------------------------------------------------------------------------------- +GlxDetailsViewItemProtoType::~GlxDetailsViewItemProtoType() +{ + int widgetIndex = modelIndex().row(); + switch (widgetIndex) { + + case widgetNameIndex: + { + delete mImageNameEditor; + mImageNameEditor = NULL; + break; + } + + case widgetDateIndex: + { + delete mDateLabel; + mDateLabel = NULL; + break; + } + + case widgetTimeIndex: + { + delete mDateLabel; + mDateLabel = NULL; + break; + } + + case widgetSizeIndex: + { + delete mSizeLabel; + mSizeLabel = NULL; + break; + } + + case widgetDescriptionIndex: + { + delete mDescriptionEditor; + mDescriptionEditor = NULL; + break; + } + + default: + break; + } + +} + +//-------------------------------------------------------------------------------------------------------------------------------------------- +//createItem +//-------------------------------------------------------------------------------------------------------------------------------------------- +HbAbstractViewItem* GlxDetailsViewItemProtoType::createItem() +{ + return new GlxDetailsViewItemProtoType(*this); +} + +//-------------------------------------------------------------------------------------------------------------------------------------------- +//updateChildItems +//-------------------------------------------------------------------------------------------------------------------------------------------- +void GlxDetailsViewItemProtoType::updateChildItems() +{ + + switch (modelIndex().row()) { + + case widgetNameIndex: + { + //create the editor + mImageNameEditor = new GlxDetailsTextEdit(this); + mImageNameEditor->setMaxRows(1); + + //retrieve the name from the model + QString nameString(GLX_DETAILS_NAME); + QVariant nameData = modelIndex().data(GlxUriRole).toString(); + if (nameData.isValid()) { + if (nameData.canConvert ()) { + nameString.append(nameData.toString()); + } + } + mImageNameEditor->setItemText(nameString); + + //Get the sub state of the details view + int substate = modelIndex().data(GlxSubStateRole).toInt(); + if (substate != IMAGEVIEWER_DETAIL_S) { + connect(mImageNameEditor, SIGNAL(editorTapped()), this, SLOT(forwardSignalsToView())); + } + else { + mImageNameEditor->setTextItemReadOnly(TRUE); + } + + //Connect the Signals + const QAbstractItemModel *model = (modelIndex().model()); + connect(model, SIGNAL(updateCustomWidgets()), this, SLOT(updateWidgetValues())); + + //Add the Layout + QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); + widgetLayout->setContentsMargins(CONTENTMARGINS,CONTENTMARGINS,CONTENTMARGINS,CONTENTMARGINS); + widgetLayout->addItem(mImageNameEditor); + setLayout(widgetLayout); + break; + } + + case widgetDateIndex: + { + //retrieve the date from the model + QString dateString; + QVariant dateData = modelIndex().data(GlxDateRole).toString(); + if (dateData.isValid()) { + if (dateData.canConvert ()) { + dateString = dateData.toString(); + } + } + + //create the label and set the data + mDateLabel = new HbLabel(this); + mDateLabel->setPlainText(dateString); + mDateLabel->setMinimumHeight(size().height() + 50); + + QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); + widgetLayout->setContentsMargins(CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS); + widgetLayout->addItem(mDateLabel); + setLayout(widgetLayout); + break; + + } + case widgetTimeIndex: + { + //retrieve the time from the model + QString timeString; + QVariant timeData = modelIndex().data(GlxTimeRole).toString(); + if (timeData.isValid()) { + if (timeData.canConvert ()) { + timeString = timeData.toString(); + } + } + + //create the label and set the data + mTimeLabel = new HbLabel(this); + mTimeLabel->setPlainText(timeString); + mTimeLabel->setMinimumHeight(size().height() + 50); + + //Add the Layout + QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); + widgetLayout->setContentsMargins(CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS); + widgetLayout->addItem(mTimeLabel); + setLayout(widgetLayout); + break; + } + + case widgetSizeIndex: + { + //retrieve the size from the model + QString sizeString; + QVariant sizeData = modelIndex().data(GlxSizeRole).toString(); + if (sizeData.isValid()) { + if (sizeData.canConvert ()) { + sizeString = sizeData.toString(); + } + } + + //create the label and set the data + mSizeLabel = new HbLabel(this); + mSizeLabel->setPlainText(sizeString); + mSizeLabel->setMinimumHeight(size().height() + 50); + + //Add the Layout + QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); + widgetLayout->setContentsMargins(CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS, CONTENTMARGINS); + widgetLayout->addItem(mSizeLabel); + setLayout(widgetLayout); + break; + } + + case widgetDescriptionIndex: + { + //create the editor + mDescriptionEditor = new GlxDetailsTextEdit(this); + mDescriptionEditor->setMaxRows(5); + + //retrieve the size from the model + QString descString(GLX_DETAILS_DESCRIPTION); + QVariant descData = modelIndex().data(GlxDescRole).toString(); + if (descData.isValid()) { + if (descData.canConvert ()) { + descString.append(descData.toString()); + } + } + mDescriptionEditor->setItemText(descString); + + //Get the sub state of the details view + int substate = modelIndex().data(GlxSubStateRole).toInt(); + if (substate != IMAGEVIEWER_DETAIL_S) { + connect(mDescriptionEditor, SIGNAL(editorTapped()), this, SLOT(forwardSignalsToView())); + } + else { + mDescriptionEditor->setTextItemReadOnly(TRUE); + } + + //Connect the Signals + const QAbstractItemModel *model = (modelIndex().model()); + connect(model, SIGNAL(updateCustomWidgets()), this, SLOT(updateWidgetValues())); + + //Add the Layout + QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0); + widgetLayout->setContentsMargins(CONTENTMARGINS,CONTENTMARGINS,CONTENTMARGINS,CONTENTMARGINS); + widgetLayout->addItem(mDescriptionEditor); + setLayout(widgetLayout); + break; + } + + default: + break; + } + + HbListViewItem::updateChildItems(); + +} + +//-------------------------------------------------------------------------------------------------------------------------------------------- +//forwardSignalsToView +//-------------------------------------------------------------------------------------------------------------------------------------------- +void GlxDetailsViewItemProtoType::forwardSignalsToView() +{ + int widgetIndex = modelIndex().row(); + emit static_cast (prototype())->signalFromCustomWidget( + widgetIndex); +} + +//-------------------------------------------------------------------------------------------------------------------------------------------- +//updateWidgetValues +//-------------------------------------------------------------------------------------------------------------------------------------------- +void GlxDetailsViewItemProtoType::updateWidgetValues() +{ + int widgetIndex = modelIndex().row(); + if (widgetIndex == GlxDetailsViewItemProtoType::widgetNameIndex) { + + QString nameString(GLX_DETAILS_NAME); + QVariant nameData = modelIndex().data(GlxUriRole).toString(); + + if (nameData.isValid()) { + if (nameData.canConvert ()) { + nameString.append(nameData.toString()); + } + } + mImageNameEditor->setItemText(nameString); + } + else { + QString descString(GLX_DETAILS_DESCRIPTION); + QVariant descData = modelIndex().data(GlxDescRole).toString(); + + if (descData.isValid()) { + if (descData.canConvert ()) { + descString.append(descData.toString()); + } + } + mDescriptionEditor->setItemText(descString); + } +} +