emailuis/nmailui/src/nmmailboxlistviewitem.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 14 May 2010 15:41:10 +0300
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 27 9ba4404ef423
permissions -rw-r--r--
Revision: 201017 Kit: 201019

/*
* 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:
*
*/

#include "nmuiheaders.h"

/*!
    \class NmMailboxListViewItem
    \brief Mailbox list view item inherited from HbListViewItem
*/

/*!
    Constructor
*/
NmMailboxListViewItem::NmMailboxListViewItem(QGraphicsItem *parent)
: HbListViewItem(parent),
mLayout(NULL)
{
}

/*!
    Destructor
*/
NmMailboxListViewItem::~NmMailboxListViewItem()
{
}

/*!
    Item creation
*/
HbListViewItem* NmMailboxListViewItem::createItem()
{
    return new NmMailboxListViewItem(*this);
}

/*!
    update child items
*/
void NmMailboxListViewItem::updateChildItems()
{
    // To create primitives
    HbListViewItem::updateChildItems();

    NmMailboxMetaData *mailbox =
            modelIndex().data(Qt::DisplayRole).value<NmMailboxMetaData*>();
    if (mailbox){
        mLayout = new QGraphicsLinearLayout(Qt::Horizontal, 0);
        mLayout->setContentsMargins(0,0,0,0);

        HbLabel *mbIcon = new HbLabel();
        mbIcon->setObjectName("MailboxListViewMailboxIcon");
        mbIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconDefaultMailbox));
        mbIcon->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);

        HbLabel *mbName = new HbLabel();
        mbName->setObjectName("MailboxListViewMailboxName");
        mbName->setPlainText(mailbox->name());
        mbName->setAlignment(Qt::AlignVCenter);
        mbName->setFontSpec(HbFontSpec(HbFontSpec::Primary));
        mbName->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

        mLayout->addItem(mbIcon);
        mLayout->addItem(mbName);
        mLayout->setItemSpacing(0,0);

        setLayout(mLayout); // Ownership is transferred
    }
}

/*!
    boolean value indicating model index availability
*/
bool NmMailboxListViewItem::canSetModelIndex(const QModelIndex &index)
{
    Q_UNUSED(index);
    return true;
}

/*!
    polishEvent. Call to base class polish event.
*/
void NmMailboxListViewItem::polishEvent()
{
    QGraphicsWidget::polishEvent();
}

/*!
    paint. Paint function for line painting.
*/
void NmMailboxListViewItem::paint(
    QPainter *painter,
    const QStyleOptionGraphicsItem *option,
    QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);
    Q_UNUSED(painter);
}