calendarui/views/dayview/src/calendayhourelement.cpp
changeset 45 b6db4fd4947b
child 55 2c54b51f39c4
child 58 ef813d54df51
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 
       
    18 //System includes
       
    19 #include <QGraphicsLinearLayout>
       
    20 #include <QPainter>
       
    21 #include <hbtextitem.h>
       
    22 #include <hbstyle.h>
       
    23 #include <hbcolorscheme.h>
       
    24 #include <hbfontspec.h>
       
    25 #include <hbextendedlocale.h>
       
    26 
       
    27 //User includes
       
    28 #include "calendayhourelement.h"
       
    29 #include "calendaycontainer.h"
       
    30 #include "calendayhourscrollarea.h"
       
    31 
       
    32 // Constants
       
    33 
       
    34 /*!
       
    35  \brief CalenDayHourElement()
       
    36  Constructor
       
    37 */
       
    38 CalenDayHourElement::CalenDayHourElement(const QTime &time, QGraphicsItem *parent) :
       
    39     HbWidget(parent), mHour(time)
       
    40 {
       
    41     // Necessary when widget implements own paint method
       
    42     setFlag(QGraphicsItem::ItemHasNoContents, false); 
       
    43 
       
    44     HbDeviceProfile deviceProfile;
       
    45     mUnitInPixels = deviceProfile.unitValue();
       
    46     
       
    47     mHourLineColor = HbColorScheme::color("qtc_cal_day_hour_lines");
       
    48 
       
    49     //Create text items
       
    50     HbExtendedLocale systemLocale = HbExtendedLocale::system();
       
    51 
       
    52     //Get current time format and (if there's a need) separate time from am/pm text
       
    53     QChar timeSeparator = ' ';
       
    54     QStringList timeTextList = systemLocale.format(time, r_qtn_time_usual_with_zero).split(
       
    55         timeSeparator);
       
    56 
       
    57     //prepend 0 if needed to achieve format - 01:00
       
    58     QString timeString = timeTextList[0];
       
    59     if (timeString.length() < 5) {
       
    60         timeString.prepend('0');
       
    61     }
       
    62 
       
    63     QString ampmString = "";
       
    64     if (timeTextList.count() > 1) {
       
    65         ampmString = timeTextList[1].toLower();
       
    66     }
       
    67 
       
    68     HbTextItem* timeTextItem = new HbTextItem(timeString, this);
       
    69     HbTextItem* ampmTextItem = new HbTextItem(ampmString, this);
       
    70 
       
    71     HbStyle::setItemName(timeTextItem, QLatin1String("time"));
       
    72     HbStyle::setItemName(ampmTextItem, QLatin1String("ampm"));
       
    73 
       
    74     mContainer = static_cast<CalenDayHourScrollArea*> (parent);
       
    75 
       
    76 }
       
    77 
       
    78 /*!
       
    79  \brief CalenDayHourElement()
       
    80  Destructor
       
    81 */
       
    82 CalenDayHourElement::~CalenDayHourElement()
       
    83 {
       
    84 
       
    85 }
       
    86 
       
    87 /*!
       
    88  \brief CalenDayHourElement()
       
    89  paint
       
    90 */
       
    91 void CalenDayHourElement::paint(
       
    92     QPainter * painter,
       
    93     const QStyleOptionGraphicsItem * option,
       
    94     QWidget * widget)
       
    95 {
       
    96     Q_UNUSED(widget);
       
    97     
       
    98     QRectF drawArea = option->rect;
       
    99 
       
   100     const qreal hourLineThickness = 0.15; //un (according to UI spec)
       
   101     const qreal timeLineThickness = 0.75; //un (according to UI spec)
       
   102 
       
   103     painter->save();
       
   104 
       
   105     //Draw full hour line
       
   106     QPen linePen = QPen(mHourLineColor, hourLineThickness * mUnitInPixels);
       
   107     painter->setPen(linePen);
       
   108     QLineF fullHourLine(drawArea.bottomLeft(), drawArea.bottomRight());
       
   109 
       
   110     painter->drawLine(fullHourLine);
       
   111 
       
   112     //Draw extra line on top for midnight
       
   113     if (mHour.hour() == 0) {
       
   114         fullHourLine = QLineF(drawArea.topLeft(), drawArea.topRight());
       
   115         painter->drawLine(fullHourLine);
       
   116     }    
       
   117     
       
   118     QDateTime currentDateTime = QDateTime::currentDateTime();
       
   119 
       
   120     //Draw the time line in theme color
       
   121     if (mContainer) {
       
   122         QDateTime containersDateTime = mContainer->dateTime();
       
   123         
       
   124         if (currentDateTime.date() == containersDateTime.date() && currentDateTime.time().hour()
       
   125             == mHour.hour()) {
       
   126 
       
   127             qreal currentTimeY = drawArea.height() * currentDateTime.time().minute() / 60;
       
   128             
       
   129             QColor color = HbColorScheme::color("qtc_cal_month_current_day");
       
   130             
       
   131             painter->setPen(QPen(color, timeLineThickness * mUnitInPixels, Qt::SolidLine,
       
   132                 Qt::FlatCap));
       
   133             QLineF currentTimeline(drawArea.left(), drawArea.top() + currentTimeY, drawArea.right(), drawArea.top()
       
   134                 + currentTimeY);
       
   135             painter->drawLine(currentTimeline);
       
   136 
       
   137         }
       
   138     }
       
   139 
       
   140     painter->restore();
       
   141 }
       
   142 
       
   143 // End of File