calendarui/views/dayview/src/calendayeventspane.cpp
changeset 45 b6db4fd4947b
child 55 2c54b51f39c4
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
       
     1 /*
       
     2 * Copyright (c) 2010 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:  Day view control of calendar
       
    15 *
       
    16 */
       
    17 // System includes
       
    18 #include <QPainter>
       
    19 #include <hbcolorscheme.h>
       
    20 
       
    21 // User includes
       
    22 #include "CalenDayEventsPane.h"
       
    23 
       
    24 /*!
       
    25  \class CalenDayEventsPane
       
    26  \brief Events pane draws timelines in content view.
       
    27  */
       
    28 
       
    29 /*!
       
    30  \brief Constructor
       
    31  
       
    32  \param parent The parent of widget
       
    33  */
       
    34 CalenDayEventsPane::CalenDayEventsPane(HbWidget *parent) : HbWidget(parent),
       
    35     mDrawTopLine(false)
       
    36 {
       
    37     // Necessary when widget implements own paint method
       
    38     setFlag(QGraphicsItem::ItemHasNoContents, false);
       
    39 
       
    40     HbDeviceProfile deviceProfile;
       
    41     mUnitInPixels = deviceProfile.unitValue();
       
    42     mHourLineColor = HbColorScheme::color("qtc_cal_day_hour_lines");
       
    43     
       
    44     // Set custom dashed pen
       
    45     mCustomDashedPen.setWidth(0.15);
       
    46     QVector<qreal> dashes;
       
    47     dashes << 5 << 5;
       
    48     mCustomDashedPen.setDashPattern(dashes);
       
    49     mCustomDashedPen.setCapStyle(Qt::FlatCap);
       
    50     mCustomDashedPen.setColor(mHourLineColor);
       
    51 }
       
    52 
       
    53 /*!
       
    54  \brief Destructor
       
    55  */
       
    56 CalenDayEventsPane::~CalenDayEventsPane()
       
    57 {
       
    58 }
       
    59 
       
    60 /*!
       
    61  \brief Shows/hides a line at top of event pane.
       
    62  
       
    63  \param drawTopLine Flag to be set if top line should be drawn.
       
    64  */
       
    65 void CalenDayEventsPane::drawTopLine(bool drawTopLine)
       
    66 {
       
    67     mDrawTopLine = drawTopLine;
       
    68 }
       
    69 
       
    70 /*!
       
    71  \brief Paints the item with given painter.
       
    72  
       
    73  \param painter
       
    74  \param option
       
    75  \param widget
       
    76  */
       
    77 void CalenDayEventsPane::paint(QPainter *painter, 
       
    78     const QStyleOptionGraphicsItem *option, QWidget *widget)
       
    79 {
       
    80     Q_UNUSED(widget)
       
    81     
       
    82     QRectF drawArea = option->rect;
       
    83     
       
    84     const qreal hourLineThickness = 0.15; //un (according to UI spec)
       
    85 
       
    86     painter->save();
       
    87     
       
    88     // Draw full hour line
       
    89     QPen linePen = QPen(mHourLineColor, hourLineThickness * mUnitInPixels);
       
    90     painter->setPen(linePen);
       
    91     QLineF fullHourLine(drawArea.bottomLeft(), drawArea.bottomRight());
       
    92     painter->drawLine(fullHourLine);
       
    93     
       
    94     // Draw extra line on top if needed
       
    95     if (mDrawTopLine) {
       
    96         fullHourLine = QLineF(drawArea.topLeft(), drawArea.topRight());
       
    97         painter->drawLine(fullHourLine);
       
    98     }
       
    99 
       
   100     // Draw half hour line
       
   101     painter->setPen(mCustomDashedPen);
       
   102     qreal halfHourYPos = drawArea.height() / 2;
       
   103     QLineF halfHourLine(drawArea.left(), halfHourYPos, drawArea.right(), halfHourYPos);
       
   104     painter->drawLine(halfHourLine);
       
   105     
       
   106     painter->restore();
       
   107 }
       
   108