calendarui/views/dayview/src/calendayhourelement.cpp
changeset 57 bb2d3e476f29
parent 55 2c54b51f39c4
child 63 a3cb48f6c889
equal deleted inserted replaced
55:2c54b51f39c4 57:bb2d3e476f29
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:  Day view control of calendar
    14  * Description:  Day view control of calendar
    15 *
    15  *
    16 */
    16  */
    17 
    17 
    18 //System includes
    18 // System includes
    19 #include <QGraphicsLinearLayout>
    19 #include <QGraphicsLinearLayout>
    20 #include <QPainter>
    20 #include <QPainter>
    21 #include <hbtextitem.h>
    21 #include <HbTextItem>
    22 #include <hbstyle.h>
    22 #include <HbStyle>
    23 #include <hbcolorscheme.h>
    23 #include <HbColorScheme>
    24 #include <hbfontspec.h>
    24 #include <HbFontSpec>
    25 #include <hbextendedlocale.h>
    25 #include <HbExtendedLocale>
    26 
    26 
    27 //User includes
    27 // User includes
    28 #include "calendayhourelement.h"
    28 #include "calendayhourelement.h"
    29 #include "calendaycontainer.h"
    29 #include "calendaycontainer.h"
    30 #include "calendayhourscrollarea.h"
    30 #include "calendayhourscrollarea.h"
    31 
    31 
    32 // Constants
    32 // Constants
       
    33 /*!
       
    34  \brief Time format is: [0-9][0-9]:[0-9][0-9]
       
    35  */
       
    36 const int KCalenTimeFormatLength = 5;
    33 
    37 
    34 /*!
    38 /*!
    35  \brief CalenDayHourElement()
    39  \class CalenDayHourElement
    36  Constructor
    40  \brief Hour element widget for Calendar's Day View
    37 */
    41  */
    38 CalenDayHourElement::CalenDayHourElement(const QTime &time, QGraphicsItem *parent) :
    42 
       
    43 /*!
       
    44  \brief Constructor
       
    45  
       
    46  \param time Time assigned to widget
       
    47  \param parent Widget's parent
       
    48  */
       
    49 CalenDayHourElement::CalenDayHourElement(
       
    50     const QTime &time,
       
    51     QGraphicsItem *parent) :
    39     HbWidget(parent), mHour(time)
    52     HbWidget(parent), mHour(time)
    40 {
    53 {
    41     // Necessary when widget implements own paint method
    54     // Necessary when widget implements own paint method
    42     setFlag(QGraphicsItem::ItemHasNoContents, false); 
    55     setFlag(QGraphicsItem::ItemHasNoContents, false);
    43 
    56 
    44     HbDeviceProfile deviceProfile;
    57     HbDeviceProfile deviceProfile;
    45     mUnitInPixels = deviceProfile.unitValue();
    58     mUnitInPixels = deviceProfile.unitValue();
    46     
       
    47     mHourLineColor = HbColorScheme::color("qtc_cal_day_hour_lines");
       
    48 
    59 
    49     //Create text items
    60     // Initialize hour line color
       
    61     mHourLineColor = HbColorScheme::color(KCalenHourLineColor);
       
    62 
       
    63     // Create text items
    50     HbExtendedLocale systemLocale = HbExtendedLocale::system();
    64     HbExtendedLocale systemLocale = HbExtendedLocale::system();
    51 
    65 
    52     //Get current time format and (if there's a need) separate time from am/pm text
    66     // Get current time format and (if there's a need) separate time from am/pm text
    53     QChar timeSeparator = ' ';
    67     QChar timeSeparator = ' ';
    54     QStringList timeTextList = systemLocale.format(time, r_qtn_time_usual_with_zero).split(
    68     QStringList timeTextList = systemLocale.format(time,
    55         timeSeparator);
    69         r_qtn_time_usual_with_zero).split(timeSeparator);
    56 
    70 
    57     //prepend 0 if needed to achieve format - 01:00
    71     // If needed, prepend '0' to get proper time format: [0-9][0-9]:[0-9][0-9]
    58     QString timeString = timeTextList[0];
    72     QString timeString = timeTextList[0];
    59     if (timeString.length() < 5) {
    73     if (timeString.length() < KCalenTimeFormatLength) {
    60         timeString.prepend('0');
    74         timeString.prepend('0');
    61     }
    75     }
    62 
    76 
    63     QString ampmString = "";
    77     QString ampmString = "";
    64     if (timeTextList.count() > 1) {
    78     if (timeTextList.count() > 1) {
    69     HbTextItem* ampmTextItem = new HbTextItem(ampmString, this);
    83     HbTextItem* ampmTextItem = new HbTextItem(ampmString, this);
    70 
    84 
    71     HbStyle::setItemName(timeTextItem, QLatin1String("time"));
    85     HbStyle::setItemName(timeTextItem, QLatin1String("time"));
    72     HbStyle::setItemName(ampmTextItem, QLatin1String("ampm"));
    86     HbStyle::setItemName(ampmTextItem, QLatin1String("ampm"));
    73 
    87 
       
    88     // Parent container is needed to update widget's time
    74     mContainer = static_cast<CalenDayHourScrollArea*> (parent);
    89     mContainer = static_cast<CalenDayHourScrollArea*> (parent);
    75 
       
    76 }
    90 }
    77 
    91 
    78 /*!
    92 /*!
    79  \brief CalenDayHourElement()
    93  \brief Destructor
    80  Destructor
    94  */
    81 */
       
    82 CalenDayHourElement::~CalenDayHourElement()
    95 CalenDayHourElement::~CalenDayHourElement()
    83 {
    96 {
    84 
    97 
    85 }
    98 }
    86 
    99 
    87 /*!
   100 /*!
    88  \brief CalenDayHourElement()
   101  \brief Customized paint() function
    89  paint
   102  
    90 */
   103  \param painter Painter
       
   104  \param option Style option
       
   105  \param widget
       
   106  */
    91 void CalenDayHourElement::paint(
   107 void CalenDayHourElement::paint(
    92     QPainter * painter,
   108     QPainter *painter,
    93     const QStyleOptionGraphicsItem * option,
   109     const QStyleOptionGraphicsItem *option,
    94     QWidget * widget)
   110     QWidget *widget)
    95 {
   111 {
    96     Q_UNUSED(widget);
   112     Q_UNUSED(widget);
       
   113 
       
   114     painter->save();
    97     
   115     
    98     QRectF drawArea = option->rect;
   116     QRectF drawArea = option->rect;
    99 
   117 
   100     const qreal hourLineThickness = 0.15; //un (according to UI spec)
   118     // Draw full hour line
   101     const qreal timeLineThickness = 0.75; //un (according to UI spec)
   119     QPen linePen = QPen(mHourLineColor, KCalenHourLineThickness * mUnitInPixels);
   102 
       
   103     painter->save();
       
   104 
       
   105     //Draw full hour line
       
   106     QPen linePen = QPen(mHourLineColor, hourLineThickness * mUnitInPixels);
       
   107     painter->setPen(linePen);
   120     painter->setPen(linePen);
       
   121     
   108     QLineF fullHourLine(drawArea.bottomLeft(), drawArea.bottomRight());
   122     QLineF fullHourLine(drawArea.bottomLeft(), drawArea.bottomRight());
   109 
       
   110     painter->drawLine(fullHourLine);
   123     painter->drawLine(fullHourLine);
   111 
   124 
   112     //Draw extra line on top for midnight
   125     // Draw extra line on top for midnight
   113     if (mHour.hour() == 0) {
   126     if (mHour.hour() == 0) {
   114         fullHourLine = QLineF(drawArea.topLeft(), drawArea.topRight());
   127         fullHourLine = QLineF(drawArea.topLeft(), drawArea.topRight());
   115         painter->drawLine(fullHourLine);
   128         painter->drawLine(fullHourLine);
   116     }    
   129     }
   117     
   130 
   118     QDateTime currentDateTime = QDateTime::currentDateTime();
   131     QDateTime currentDateTime = QDateTime::currentDateTime();
   119 
   132 
   120     //Draw the time line in theme color
   133     // Draw the time line in theme color
   121     if (mContainer) {
   134     if (mContainer) {
   122         QDateTime containersDateTime = mContainer->dateTime();
   135         QDateTime containersDateTime = mContainer->dateTime();
   123         
       
   124         if (currentDateTime.date() == containersDateTime.date() && currentDateTime.time().hour()
       
   125             == mHour.hour()) {
       
   126 
   136 
   127             qreal currentTimeY = drawArea.height() * currentDateTime.time().minute() / 60;
   137         if (currentDateTime.date() == containersDateTime.date()
   128             
   138             && currentDateTime.time().hour() == mHour.hour()) {
   129             QColor color = HbColorScheme::color("qtc_cal_month_current_day");
   139 
   130             
   140             qreal currentTimeY = drawArea.height()
   131             painter->setPen(QPen(color, timeLineThickness * mUnitInPixels, Qt::SolidLine,
   141                 * currentDateTime.time().minute() / 60;
   132                 Qt::FlatCap));
   142 
   133             QLineF currentTimeline(drawArea.left(), drawArea.top() + currentTimeY, drawArea.right(), drawArea.top()
   143             QColor color = HbColorScheme::color(KCalenTimeLineColor);
   134                 + currentTimeY);
   144             painter->setPen(QPen(color, KCalenTimeLineThickness * mUnitInPixels,
       
   145                 Qt::SolidLine, Qt::FlatCap));
       
   146             QLineF currentTimeline(drawArea.left(), drawArea.top() + currentTimeY,
       
   147                     drawArea.right(), drawArea.top() + currentTimeY);
   135             painter->drawLine(currentTimeline);
   148             painter->drawLine(currentTimeline);
   136 
       
   137         }
   149         }
   138     }
   150     }
   139     
       
   140 
   151 
   141     painter->restore();
   152     painter->restore();
   142 }
   153 }
   143 
   154 
   144 /*!
   155 /*!
   145    \brief It set time for hour element.
   156  \brief Sets time for hour element.
       
   157  
       
   158  \param time Time to be set for hour element
   146  */
   159  */
   147 void CalenDayHourElement::setTime(const QTime &time)
   160 void CalenDayHourElement::setTime(const QTime &time)
   148 {
   161 {
   149     mHour = time;
   162     mHour = time;
   150 }
   163 }
   151 
   164 
   152 /*!
   165 /*!
   153    \brief It return time of hour element.
   166  \brief Returns time of hour element.
       
   167  
       
   168  \return Time of hour element
   154  */
   169  */
   155 QTime CalenDayHourElement::time() const
   170 QTime CalenDayHourElement::time() const
   156 {
   171 {
   157     return mHour;
   172     return mHour;
   158 }
   173 }