calendarui/views/dayview/src/calendayeventspane.cpp
author hgs
Mon, 28 Jun 2010 15:22:02 +0530
changeset 45 b6db4fd4947b
child 55 2c54b51f39c4
permissions -rw-r--r--
201025

/*
* Copyright (c) 2010 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:  Day view control of calendar
*
*/
// System includes
#include <QPainter>
#include <hbcolorscheme.h>

// User includes
#include "CalenDayEventsPane.h"

/*!
 \class CalenDayEventsPane
 \brief Events pane draws timelines in content view.
 */

/*!
 \brief Constructor
 
 \param parent The parent of widget
 */
CalenDayEventsPane::CalenDayEventsPane(HbWidget *parent) : HbWidget(parent),
    mDrawTopLine(false)
{
    // Necessary when widget implements own paint method
    setFlag(QGraphicsItem::ItemHasNoContents, false);

    HbDeviceProfile deviceProfile;
    mUnitInPixels = deviceProfile.unitValue();
    mHourLineColor = HbColorScheme::color("qtc_cal_day_hour_lines");
    
    // Set custom dashed pen
    mCustomDashedPen.setWidth(0.15);
    QVector<qreal> dashes;
    dashes << 5 << 5;
    mCustomDashedPen.setDashPattern(dashes);
    mCustomDashedPen.setCapStyle(Qt::FlatCap);
    mCustomDashedPen.setColor(mHourLineColor);
}

/*!
 \brief Destructor
 */
CalenDayEventsPane::~CalenDayEventsPane()
{
}

/*!
 \brief Shows/hides a line at top of event pane.
 
 \param drawTopLine Flag to be set if top line should be drawn.
 */
void CalenDayEventsPane::drawTopLine(bool drawTopLine)
{
    mDrawTopLine = drawTopLine;
}

/*!
 \brief Paints the item with given painter.
 
 \param painter
 \param option
 \param widget
 */
void CalenDayEventsPane::paint(QPainter *painter, 
    const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(widget)
    
    QRectF drawArea = option->rect;
    
    const qreal hourLineThickness = 0.15; //un (according to UI spec)

    painter->save();
    
    // Draw full hour line
    QPen linePen = QPen(mHourLineColor, hourLineThickness * mUnitInPixels);
    painter->setPen(linePen);
    QLineF fullHourLine(drawArea.bottomLeft(), drawArea.bottomRight());
    painter->drawLine(fullHourLine);
    
    // Draw extra line on top if needed
    if (mDrawTopLine) {
        fullHourLine = QLineF(drawArea.topLeft(), drawArea.topRight());
        painter->drawLine(fullHourLine);
    }

    // Draw half hour line
    painter->setPen(mCustomDashedPen);
    qreal halfHourYPos = drawArea.height() / 2;
    QLineF halfHourLine(drawArea.left(), halfHourYPos, drawArea.right(), halfHourYPos);
    painter->drawLine(halfHourLine);
    
    painter->restore();
}